#!/usr/local/bin/perl -w use strict; # phost - host command implemented in Perl # Andrew Ho (andrew@tellme.com) use Socket; foreach(@ARGV) { chomp; s/\s+//gsm; my $hostname = $_; if(/^(\d+\.\d+\.\d+\.\d+)$/) { # Looks like an IP $hostname = gethostbyaddr inet_aton($1), AF_INET; } if($hostname) { my @hostinfo = gethostbyname $hostname; if(@hostinfo) { my($name, @ips) = @hostinfo[0, 4 .. $#hostinfo]; foreach(@ips) { my $ip = inet_ntoa $_; print "$name has address $ip"; my $reverse = gethostbyaddr inet_aton($ip), AF_INET; print " ($reverse)" if $reverse && $reverse ne lc $hostname; print "\n"; } } else { print "Host not found.\n"; } } else { print "Host not found.\n"; } } exit 0; __END__