Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Getting my IP adresses

by ruoso (Curate)
on May 14, 2007 at 16:59 UTC ( [id://615383]=CUFP: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-16 14:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found