[RndTbl] determine IP address in linux

Trevor Cordes trevor at tecnopolis.ca
Sun Mar 24 18:06:09 CDT 2013


On 2013-03-23 Sean Walberg wrote:
> my_public_ip=`curl http://ifconfig.me`

Hehe, ya, but won't help me when I have an IP but my internet is down
(dropping packets, or iptables bungled).

On 2013-03-24 Kevin McGregor wrote:
> ifconfig eth0 | grep inet[^6] | awk  -F"[: \t]+" '{print $4}' # Get

Doesn't fit the requirement of not relying on (now proven) changeable
strings ("inet") and position ($4).  :-(

On 2013-03-24 Adam Thompson wrote:
> There is (AFAIK) no generic, portable, standardized solution.

Afraid of that...

> 1. No UNIX system is guaranteed to have networking at all, never mind 
> TCP/IP.
> 2. POSIX doesn't cover networking configuration commands (that I can 
> find, anyway)

Luckily for me I don't care at all about this working on anything other
than Fedora 17 and newer.  The tricky part is I want to work for as
many "newer" Fedoras as possible.  For instance, if there was a /sys
file made by the kernel then there's a good chance Linus would never
let it change.  Whereas userland stuff like "ifconfig" and "ip" seem
mutable at the whims of the authors :-(

Your script is good.  Whittled down to just the case I care about (has
ip command; ipv4 only; etc) it's pretty much what I've already written.

You'd think there'd be some other way though...

> can't do it from shell.  Use 
> AF_NETLINK, which is what ip(8) does internally.  Bad design, IMHO... 

So if I whipped up a little C proggie I could rely on it not to
change?  Hmm, maybe that's the way to go, but then I have to worry
about keeping compiled binaries up to date :-(

Thanks guys!


More information about the Roundtable mailing list