我尝试过以两种不同的方式获取计算机的IP地址。第一种方式是Google ip address
。第二种方法是在Java中运行以下代码:
public class YourIPAddress {
public static void main(String[] args) {
InetAddress ip;
try {
ip = InetAddress.getLocalHost();
System.out.println(ip);
System.out.println("Current IP address : " + ip.getHostAddress());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
Google返回50.90.142.29
,而Java返回192.168.0.11
。为什么IP地址发生冲突?
答案 0 :(得分:1)
192.160.0.11是私有/内部IP地址,而50.90.142.29是公共/外部IP地址