Looks like haukex may have solved your problem above, so just an observation:
- It's 2017, we really should be using address family independent Socket routines.
Unless you're *guaranteed* that:
- @ips will only be IPv4 addresses, or
- you're on a Perl older than 5.14, or
- your Socket module version is older than 1.94, or
- you're using an operating system circa Windows XP ...
you may encounter IPv6. So planning for it is easy:
#!perl
use strict;
use warnings;
my @bla = qw ( 34.230.53.172 2607:f8b0:400d:c0b::63 );
for my $bla (@bla) {
### What you need below ###
use Socket qw( AF_INET IPPROTO_TCP );
my $AF_UNSPEC = eval { Socket::AF_UNSPEC() };
my $NI_NAMEREQD = eval { Socket::NI_NAMEREQD() };
my %hints = (
family => $AF_UNSPEC,
protocol => IPPROTO_TCP
);
my ( $err, @getaddr ) = Socket::getaddrinfo( $bla, undef, \%hints );
for my $addr (@getaddr) {
my ( $err, $host, $service )
= Socket::getnameinfo( $addr->{addr}, $NI_NAMEREQD );
printf "%s\n", ( defined($host) ) ? $host : $err;
}
### What you need above ###
}