Skip to content

Instantly share code, notes, and snippets.

@b4hand
Last active December 20, 2015 18:49
Show Gist options
  • Save b4hand/6178774 to your computer and use it in GitHub Desktop.
Save b4hand/6178774 to your computer and use it in GitHub Desktop.
Do an IP to name resolution from the command line
perl -e 'use Socket qw(getnameinfo inet_aton pack_sockaddr_in NI_NUMERICSERV); my $ip = inet_aton($ARGV[0]); my $addr = pack_sockaddr_in(80, $ip); my ($err, $hostname) = getnameinfo($addr, NI_NUMERICSERV); print "$hostname\n"'
@b4hand
Copy link
Author

b4hand commented Dec 16, 2013

This one-liner expects a single IP address argument to be passed on the command line.

The advantage to this one liner is that it only uses Socket which is a standard library module of Perl, and thus works on every machine that has Perl installed, which is even more common than having the bind libraries.

You may also be interested in name_to_ip which does a forward DNS lookup in a one-liner.

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