Skip to content

Instantly share code, notes, and snippets.

@b4hand
Last active June 12, 2019 00:43
Show Gist options
  • Select an option

  • Save b4hand/6178703 to your computer and use it in GitHub Desktop.

Select an option

Save b4hand/6178703 to your computer and use it in GitHub Desktop.
Resolve a hostname to all IPs via command line (IPv4 or IPV6)
perl -e 'use Socket qw(getaddrinfo getnameinfo NI_NUMERICSERV NI_NUMERICHOST); my ($err, @res) = getaddrinfo($ARGV[0], "www", {socktype => SOCK_STREAM}); for my $r (@res) { my ($err, $ip) = getnameinfo($r->{addr}, NI_NUMERICHOST | NI_NUMERICSERV); print "$ip\n";}'
@b4hand
Copy link
Author

b4hand commented Dec 16, 2013

You may also be interested in ip_to_name which does a reverse DNS lookup in a one-liner.

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