how to retrieve IP address of a machine

hi

is there is any command that retrieves the IP address of a machine. Also is there any function in c that does the same.

thankx

Depends on the exact os and on how the box is configured. Also a box can have many ip addresses. With any fully qualified domain name, you can lookup the ip addresses. Can we assume that you know the fqdn?

One exception: the machine's ip address is 127.0.0.1. Every system can contact itself using this address.

While Perderabo is right about the myriad of configurations a given box can have, on just about every Unix I've dealt with, 'ifconfig -a' will list the configuration, including IP address, for all your network interfaces. Dunno about the C function.

Also, it's certainly possible to configure a machine with no loopback interface. On BSD for example, just run 'ifconfig lo0 delete'. Of course, that'll probably break a lot of stuff :wink:

#
#
# uname -srm
HP-UX B.11.11 9000/800
# ifconfig -a
ifconfig: no such interface
#
The rfcs state that  address 127.0.0.1 must never leave the originating system.  Deleting the loopback interface will cause packets addressed to the loopback address to generate an error and this error constitutes a "contact".  ;-\)

ipconfig/all

"ipconfig -an"