java中的IP地址冲突

时间:2013-05-31 01:22:14

标签: java ip-address

我尝试过以两种不同的方式获取计算机的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地址发生冲突?

1 个答案:

答案 0 :(得分:1)

192.160.0.11是私有/内部IP地址,而50.90.142.29是公共/外部IP地址