I just wanted to point out the use of this module, because I need to find my IP address inside some script from time to time, and I just found Net::Interface.

With the following code, I find my IP addresses

map { join '.', unpack "CCCC", scalar $_->address() } Net::Interface->interfaces();

Or, to find out if a $ip is one of mine...

grep { $_ eq $ip } map { join '.', unpack "CCCC", scalar $_->address() } Net::Interface->interfaces();
daniel

Replies are listed 'Best First'.
Re: Getting my IP adresses
by cengineer (Pilgrim) on May 15, 2007 at 14:39 UTC
    Here's another way to get the IP addresses of your interfaces using IO::Interface and IO::Socket:
    #!/usr/bin/perl use strict; use warnings; use IO::Interface; use IO::Socket; # Create a simple socket to use with interfaces my $s = IO::Socket::INET->new(Proto => 'udp'); # Get list of interfaces my @interfaces = $s->if_list; my $addr; # Iterate over list of interfaces foreach (@interfaces) { $addr = $s->if_addr($_); print "interface = $_ : address = $addr\n"; }