#!/usr/bin/perl use strict; use warnings; use Getopt::Long qw(:config no_ignore_case); use Pod::Usage; use Socket; use Socket6; # Windows DOES support getaddrinfo and inet_ntop/pton functions # although it may *seem* like it doesn't from Strawberry's GCC # Don't need Socket6::GetAddrInfo my %opt; GetOptions( 'new!' => \$opt{new}, 'old!' => \$opt{old} ) or pod2usage(-verbose => 0); if (!@ARGV) { pod2usage(-verbose => 0, -message => "$0: host required\n") } if ((!defined($opt{new})) && (!defined($opt{old}))) { $opt{new} = $opt{old} = 1 } if ($opt{old}) { my $gethost = gethostbyname($ARGV[0]); my $host = inet_ntoa((gethostbyname($ARGV[0]))[4]); # print "OLD: gethostbyname() = $gethost\n"; print "OLD: inet_ntoa() Address = $host\n"; } if ($opt{new}) { my @getaddr = getaddrinfo($ARGV[0], 0); # IP[v6] address shows up at different locations in the [3] element # use substr to 'find' it - awful! my $host = inet_ntop($getaddr[0], substr($getaddr[3], (($getaddr[0] == AF_INET) ? 4 : 8), (($getaddr[0] == AF_INET) ? 4 : 16))); # printf "NEW: getaddrinfo() = %s\n", $getaddr[3]; print "NEW: inet_ntop() Address = $host\n"; } __END__ =head1 SYNOPSIS program [--old|--new] IP[v6]_address | hostname