Querying IP Address of a NIC

J

Joe Van Dyk

Hi,

Other than parsing the output of `sudo /sbin/ifconfig`, anyone know of
a way to get the current IP address of a NIC? (say, eth0).

Thanks!
Joe
 
D

Detlef Reichl

Am Dienstag, den 18.10.2005, 03:01 +0900 schrieb Joe Van Dyk:
Hi,

Other than parsing the output of `sudo /sbin/ifconfig`, anyone know of
a way to get the current IP address of a NIC? (say, eth0).

on linux systems its in /sys/class/net/eth0/address

If some day someone provides bindings to the hardware abstraction layer
(libhal) you could query it from there :)

Cheers
detlef
 
G

Gábor SEBESTYÉN

--Apple-Mail-1-943152680
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=UTF-8;
format=flowed


Other than parsing the output of `sudo /sbin/ifconfig`, anyone know of
a way to get the current IP address of a NIC? (say, eth0).
Try this:

ifconfig en0 inet | grep inet | awk '{print $2}'

Where "en0" is the subject of query.
Cheers,

G=C3=A1bor

"=C3=A9rtelmez=C5=91 k=C3=A9zisz=C3=B3t=C3=A1r: rekurzi=C3=B3 --> l=C3=A1s=
d: rekurzi=C3=B3"



--Apple-Mail-1-943152680--
 
Y

Yohanes Santoso

Joe Van Dyk said:
Hi,

Other than parsing the output of `sudo /sbin/ifconfig`, anyone know of
a way to get the current IP address of a NIC? (say, eth0).

Thanks!
Joe

Parsing ifconfig is the only method that works on the largest number
of OSes.

Other than that, you'd have to use OS-dependent feature like what
Detlef Reichl has shown.

YS.
 
D

Dick Davies

Hi,

Other than parsing the output of `sudo /sbin/ifconfig`, anyone know of
a way to get the current IP address of a NIC? (say, eth0).

Well, you don't need to run it under sudo..... :)
 
G

Guillaume Marcais

Am Dienstag, den 18.10.2005, 03:01 +0900 schrieb Joe Van Dyk:

on linux systems its in /sys/class/net/eth0/address

That looks like the Mac address, not the IP address.
If some day someone provides bindings to the hardware abstraction layer
(libhal) you could query it from there :)


I actually have some code wrapping rtnetlink socket, which can get you
lots of routing information (man 7 rtnetlink). Although I use this code
to query the bandwidth manager on live machines, the code has a memory
leak, is alpha quality and fairly incomplete. I think rtnetlink is
pretty much Linux specific too.

If there is enough interest to pump up my motivation, I'll try to finish
it.

Guillaume.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top