为什么我用下面的方法获得的主机名和IP地址始终是localhost和127.0.0.1,而不是我的真实IP192.168.1.25
package nettest; import java.net.*; public class NetTest1 {
public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub InetAddress i=InetAddress.getLocalHost(); System.out.println(i.toString()); System.out.println(i.getHostAddress()); System.out.println(i.getHostName()); }
}
|