Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Answer: List all network interfaces on the local machine?

( #166951=categorized answer: print w/ replies, xml ) Need Help??

Q&A > network programming > List all network interfaces on the local machine? contributed by dada

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"; }

Comment on Answer: List all network interfaces on the local machine?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2014-09-18 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (113 votes), past polls