Last active
June 12, 2019 00:43
-
-
Save b4hand/6178703 to your computer and use it in GitHub Desktop.
Resolve a hostname to all IPs via command line (IPv4 or IPV6)
This file contains hidden or 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
| 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";}' |
Author
Author
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
This one-liner expects a single 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. Plus, this uses the actual system call that most programs use for doing name lookups, so it will not bypass /etc/hosts; whereas, the
hostanddigcommands ignore /etc/hosts.