home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.madoka.org
/
2014.12.ftp.madoka.org.tar
/
ftp.madoka.org
/
pub
/
plum
/
2.x
/
plum2_15_4.lzh
/
support
/
clientname
next >
Wrap
Text File
|
1997-12-21
|
1KB
|
53 lines
#!/bin/perl -w
# $Id: clientname,v 2.3 1997/12/21 13:56:36 hasegawa Exp $
# copyright (c)1997 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;
}
}
} else {
eval 'use Socket';
$SOCKET = 'Socket.pm' unless $@;
}
$AF_INET = &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";
}