我试图执行以下代码。我是Java新手,所以这是我第一次在java.net中。有一个在程序中没有错误,但我得到本地主机地址192.168.56.1作为我的,而IP是192.168.2.10getLocalHost()显示错误的IP地址
import java.net.*;
class InetAddressDemo
{
public static void main(String[] args)
{
try
{
InetAddress address = InetAddress.getLocalHost();
System.out.println("\nLocalhost Address : " + address + "\n");
}
catch (Exception e)
{
System.out.println(e);
}
}
}
你可以在这里找到一个很好的解释关于那个http://stackoverflow.com/questions/9481865/getting-the-ip-address-of-the-current-machine-using-java –