Possible Duplicate:
Get IP address of an interface on linux
How can I get the 开发者_如何学编程ip address from the device name (Example: eth0)?
DISCLAIMER: Your application SHOULD NOT depend on this kind of information. The application must see and use IP addresses ONLY. Ethernet devices are operating system plumbing. Keep in mind that you may have IP addresses not associated with any device, or devices with multiple IP addresses, multiple protocols (IPv4, IPv6), etc. Recheck the design of your application if it is really expecting to use IP addresses associated to Ethernet device names.
If you still want to associate IP addresses and Ethernet device names, check getifaddrs(3), which is a simple frontend to netlink(7) kernel sockets.
ip addr
or
ip addr show eth0
or the obsolete
ifconfig eth0
And this is a question or serverfault.com
Look here. If you need to use your result in a C program, you can use system(yourCommand)
and then fopen()
stdout to read the result.
精彩评论