home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.madoka.org
/
2014.12.ftp.madoka.org.tar
/
ftp.madoka.org
/
pub
/
plum
/
2.x
/
plum2_28_2.lzh
/
support
/
clientname
< prev
next >
Wrap
Text File
|
1998-10-15
|
1KB
|
60 lines
#!/bin/perl -w
# $Id: clientname,v 2.7 1998/10/06 04:30:34 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, @addr, $name);
if (@args < 1) {
&usage;
exit(1);
}
($host) = @args;
if ($host =~ /^\d+$/) {
$addr = pack('N', $host);
} elsif ($host =~ /^[\d\.]+$/) {
@addr = split(/\./, $host);
$addr = pack('C4', @addr, 0, 0, 0);
} else {
$addr = (gethostbyname($host))[4] || "\0\0\0\0";
}
if ($addr && $addr ne "\0\0\0\0") {
$name = (gethostbyaddr($addr, $AF_INET))[0];
if ($name) {
print $name, "\n";
print join('.', unpack('C4', $addr)), "\n";
print unpack('N', $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";
}