开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜