Getting IP in a script

Rusty Carruth rustyc@descomp.com
Wed, 21 Mar 2001 10:16:52 -0700


Kevin Buettner wrote:
> 
> On Mar 13, 12:06pm, Lucas Vogel wrote:
> 
> > To find that glibc call, would it help to look in the sources of the
> > ifconfig program? I'm curious as to the process of finding the appropriate
> > function call here...
> 
> Yes, looking at the source to ifconfig (or using strace on ifconfig as
> Deepak did) is often the quickest way to find something like this out.
> 
> Actually, before I looked at the ifconfig sources, I poked around
> /proc for a while thinking the information would be there.  If
> it's there, I didn't see it.  I think it'd be handy to have (e.g.) a
> /proc/net/devs/eth0 which would provide you with this information.
> 
> The strange thing is that there is a /proc/net/dev which lists the
> interfaces and certain statistics.

Well, I decided to dig in /proc also, and of course ended up in
/proc/net
like Kevin did.  However, I noticed something - /proc/net/tcp looks
like
it has ip addresses in hex, in reverse octet order!    Now all that's
left
to be done is figure out how to map to which interface the line is
referencing...

Ok, I looked at it a bit more, and it looks like net/tcp is a version
of
part of what you get by saying netstat -an.  Which implies that you'll 
need a connection from the outside world to the machine in order to
find yourself...  yuck.

(Its also in /proc/net/rt_cache, but that file looks like a cache of
routing info, and so I'm not too sure its going to be helpful, but
maybe
its better than ../tcp, once we know how to convert it to something
useful...)

And I dug around just about everywhere else in /proc and saw nothing
else looking even remotely like an ip address anywhere, sorry!

rc