Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

finding ip address without hostname

by c (Hermit)
on Dec 11, 2002 at 04:09 UTC ( #219002=perlquestion: print w/replies, xml ) Need Help??

c has asked for the wisdom of the Perl Monks concerning the following question:

I am in need of finding my local machine's IP address assigned to ETH0. I need to get the information independent of resolving a hostname. Instead, I need to pull information from something similar to ifconfig. I could certainly backtick the command into the code and parse out the information, but I would think there would be a cleaner, easier way. Aside from all of the nodes referencing how to find an ip address using Sys::Hostname, I've only found one that address my needs, and I don't think its the best way of doing things.

Is there a better manner, a module or built-in function that may do the trick?

-c

Replies are listed 'Best First'.
Re: finding ip address without hostname
by pg (Canon) on Dec 11, 2002 at 04:21 UTC
    Go CPAN, check out Net::Interface module.
Re: Finding an IP Address without the hostname
by cjf-II (Monk) on Dec 11, 2002 at 05:26 UTC

    Looking at the source of Sys::HostIP it appears to parse ifconfig output to obtain the IP address.

Re: finding ip address without hostname
by Abigail-II (Bishop) on Dec 11, 2002 at 10:44 UTC
    You seem to be thinking that calling an external program is "unclean". Why? It might actually be the most portable way of doing so, and it's certainly not hard.

    Abigail

Re: finding ip address without hostname
by Aristotle (Chancellor) on Dec 11, 2002 at 14:24 UTC
    A gotcha to keep in mind: a machine can have multiple IP addresses (even if it only has a single interface!). If you donīt go via the hostname, be sure to allow the user or admin to override your IP detection.

    Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://219002]
Approved by newrisedesigns
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2021-06-14 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (64 votes). Check out past polls.

    Notices?