开发者

Get my own IP address

开发者 https://www.devze.com 2023-02-27 05:18 出处:网络
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.

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

精彩评论

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