Skip to content

Instantly share code, notes, and snippets.

@gabber12
Created January 1, 2020 07:15
Show Gist options
  • Save gabber12/5b1471ee3291b82bc20c142c7cad0ca8 to your computer and use it in GitHub Desktop.
Save gabber12/5b1471ee3291b82bc20c142c7cad0ca8 to your computer and use it in GitHub Desktop.
Perl script to call gethostbyname or gethostbyaddr
#!/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");
}
@gabber12
Copy link
Author

gabber12 commented Jan 1, 2020

Example Usage

./gethost.pl host www.google.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment