Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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?


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.


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?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2023-02-06 12:14 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (34 votes). Check out past polls.