【发布时间】:2015-04-28 10:49:27
【问题描述】:
我的代码总是返回环回 ip 而不是我的 IP 是 192.168。.
try {
ip = InetAddress.getLocalHost();
System.out.println("Current IP address : " + ip.getHostAddress());
} catch (UnknownHostException e) {
e.printStackTrace();
}
【问题讨论】:
-
你能解释一下我的代码总是返回环回
-
也许这篇文章可以帮到你:stackoverflow.com/questions/9481865/…
-
他获取的是私有网络上计算机的环回(内部)IP 地址,而不是公共 IP 地址。但是这个问题是重复的。
-
我总是得到 127.0.1.1