Created
January 1, 2020 07:15
-
-
Save gabber12/5b1471ee3291b82bc20c142c7cad0ca8 to your computer and use it in GitHub Desktop.
Perl script to call gethostbyname or gethostbyaddr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use Socket; | |
die("usage: gethostby-lookup name hostname\ngetbhostby-lookup addr ip\n") unless(defined($ARGV[0]) and defined($ARGV[1])); | |
if($ARGV[0] eq "host") { | |
$packed_ip = gethostbyname("$ARGV[1]"); | |
if (defined $packed_ip) { | |
$ip_address = inet_ntoa($packed_ip); | |
print "$ip_address\n"; | |
} | |
} elsif($ARGV[0] eq "addr") { | |
$iaddr = inet_aton("$ARGV[1]"); # or whatever address | |
$name = gethostbyaddr($iaddr, AF_INET); | |
print "$name\n"; | |
} else { | |
die("usage: gethostby-lookup name hostname\ngetbhostby-lookup addr ip\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example Usage
./gethost.pl host www.google.com