home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.madoka.org
/
2014.12.ftp.madoka.org.tar
/
ftp.madoka.org
/
pub
/
plum
/
2.x
/
plum2_26_1.lzh
/
support
/
clientname
< prev
next >
Wrap
Text File
|
1998-07-31
|
1KB
|
58 lines
#!/bin/perl -w
# $Id: clientname,v 2.6 1998/02/20 19:45:26 hasegawa Exp $
# copyright (c)1997-1998 pupu_j <hasegawa@agusa.nuie.nagoya-u.ac.jp>
if ($] < 5) {
foreach $inc (@INC) {
if (-r "$inc/sys/socket.ph") {
eval { require 'sys/socket.ph' };
$SOCKET = "$inc/sys/socket.ph" unless $@;
last;
}
if (-r "$inc/socket.ph") {
eval { require 'socket.ph' };
$SOCKET = "$inc/socket.ph" unless $@;
last;
}
}
} else {
eval 'use Socket';
$SOCKET = 'Socket.pm' unless $@;
}
$AF_INET = eval { &AF_INET } || 2;
&main(@ARGV);
sub main {
local(@args) = @_;
local($host, $addr, $name);
if (@args < 1) {
&usage;
exit(1);
}
($host) = @args;
if ($host =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/) {
$addr = pack('C4', $1, $2, $3, $4);
} elsif ($host =~ /^\d+$/) {
$addr = pack('N', $host);
} else {
$addr = (gethostbyname($host))[4];
}
if ($addr) {
$name = (gethostbyaddr($addr, $AF_INET))[0];
if ($name) {
print $name, "\n";
print join('.', unpack('C4', $addr)), "\n";
} else {
print "no hostname for ", join('.', unpack('C4', $addr)), "\n";
}
} else {
print "hostname lookup failed for $host\n";
}
}
sub usage {
print "usage: perl clientname {<hostname>|<ip-address>}\n";
}