[Chicago-talk] Any handy operators for finding the local IP?

Steve Peters steve at fisharerojo.org
Tue Mar 15 13:37:57 PST 2005


On Tue, Mar 15, 2005 at 02:58:11PM -0600, wsmith wrote:
> my @ip_addresses = `/sbin/ifconfig | grep 'inet addr:' | sed -e
> 's/.*inet addr://' -e 's/ .*//'`
> 
> On Tue, 2005-03-15 at 13:50 -0600, Andy Lester wrote:
> > On Tue, Mar 15, 2005 at 01:45:38PM -0600, Steve Peters (steve at fisharerojo.org) wrote:
> > > The ways to get an IP address from Perl are less than 100% reliable.  To 
> > 
> > Please also note that chances are your machine answers to at least two
> > different IPs: 127.0.0.1, and the outside.  Heaven help you if you
> > answer to multiple IPs, on multiple interfaces, or even on the same
> > interface!
> > 
> 

That, unfortunately, makes assumptions about the location, availability, and
required parameters for ifconfig.  It will work in a single platform Linux 
environments, but it is not portable, and won't work if you work with Windows or
certain BSDs. 

Steve Peters
steve at fisharerojo.org


More information about the Chicago-talk mailing list