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 ###
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.