| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
## Originally by Ben H. Originally by neeko. |
| 4 |
## Ref: http://www.thenetworkadministrator.com/hack/IPAddresses.htm |
| 5 |
## Modified by Steven Shiau <steven _at_ clonezilla org>. |
| 6 |
## Usage: drbl-gethostip host/ip |
| 7 |
## |
| 8 |
use Socket; # for gethostbyname() |
| 9 |
use Math::BigInt; # so it fits.. |
| 10 |
my $host, @ip; # get some vars started. |
| 11 |
|
| 12 |
if ( $#ARGV < 0 ) { |
| 13 |
print "Usage: $0 host \n"; |
| 14 |
exit 1; |
| 15 |
} |
| 16 |
|
| 17 |
$name = $ARGV[0]; |
| 18 |
@host = gethostbyname( $name ); # get the ip, if a hostname is used |
| 19 |
$foo = $host[4]; |
| 20 |
# This parses the result of the gethostbyname into numbers |
| 21 |
for $n (1..4) { |
| 22 |
$ip[$n] = ord( substr( $foo , ($n-1) , 1 ) ); |
| 23 |
} |
| 24 |
my $check = $ip[1] + $ip[2] + $ip[3] + $ip[4]; |
| 25 |
if ( $check == 0) { |
| 26 |
print "$name: Unknown host\n"; |
| 27 |
exit 1 |
| 28 |
} |
| 29 |
|
| 30 |
for $n (1..4) { |
| 31 |
$ip[$n] = uc(sprintf("%02x", $ip[$n])); |
| 32 |
} |
| 33 |
|
| 34 |
print ($ip[1],$ip[2],$ip[3],$ip[4]); |
| 35 |
print "\n"; |
| 36 |
exit 0; |