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

Pete Krawczyk mongers at bsod.net
Tue Mar 15 13:32:36 PST 2005


Subject: Re: [Chicago-talk] Any handy operators for finding the local IP?
From: wsmith <warren at warrenandrachel.com>
Date: Tue, 15 Mar 2005 14:58:11 -0600

}my @ip_addresses = `/sbin/ifconfig | grep 'inet addr:' | sed -e 's/.*inet addr://' -e 's/ .*//'`

That's not very portable, especially running on a Windows box, or across 
other platforms.  For example, Mac OS X's inet lines for lo look like:

        inet6 ::1 prefixlen 128 
        inet6 fe80::1 prefixlen 64 scopeid 0x1 
        inet 127.0.0.1 netmask 0xff000000

And if you choose to dismiss that as "Well, it's only going to run on this 
box", then why not hardcode the IP in anyway?

-Pete K 
-- 
Pete Krawczyk
  mongers at bsod dot net



More information about the Chicago-talk mailing list