Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Push to Reference

by VinsWorldcom (Prior)
on Oct 10, 2017 at 11:07 UTC ( [id://1201096]=note: print w/replies, xml ) Need Help??


in reply to Push to Reference

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 ### }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1201096]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-19 18:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found