Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: List all network interfaces on the local machine?

by dada (Chaplain)
on May 16, 2002 at 08:35 UTC ( #166951=note: print w/replies, xml ) Need Help??


in reply to List all network interfaces on the local machine?

well, if you just need IP addresses, this works on Win32 and Linux and doesn't require any external module:
my @ip = (); my($name,$aliases,$addrtype,$length,@addrs) = gethostbyname('localhost +'); # @addrs should contain the loopback - 127.0.0.1 # you can skip it if you want foreach my $addr (@addrs) { push(@ip, join('.', unpack('C4', $addr))); } ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname($name); # @addrs contains our public IP address(es) foreach my $addr (@addrs) { push(@ip, join('.', unpack('C4', $addr))); } foreach my $ip (@ip) { print $ip, "\n"; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2022-11-28 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?