Get my own IP address
If I use getHostByName()
I only get "127.0.0.1", because it is written on /etc/host, but this is not usefu开发者_如何学Pythonl to me.
However, with the following java code I actually get what I want:
NetworkInterface.getByName(("eth0")).getInetAddresses().nextElement().getHostAddress()
I think that there is a way to get the same ip address also from C?
Check out getifaddrs
.
That indicates the notorious Linux /etc/hosts misconfiguration problem. The hosts file should map 127.0.0.1 to localhost, and your real IP address to your real hostname.
精彩评论