大家好,我的电脑是双网卡,我如何才能获得外网的IP
地址呢。String localIP = InetAddress.getLocalHost().getHostAddress();使用上面的语句只能获取IP地址为127.0.0.1,我如何才能获得我的外网IP呢??(10.163.162.184)谢谢大家!
地址呢。String localIP = InetAddress.getLocalHost().getHostAddress();使用上面的语句只能获取IP地址为127.0.0.1,我如何才能获得我的外网IP呢??(10.163.162.184)谢谢大家!
import java.net.UnknownHostException;public class Test1{
public static void main(String[] args){
try {
// abc123为你的主机名称
InetAddress hosts[] = InetAddress.getAllByName("abc123");
for( int i=0; i < hosts.length; i ++ ) {
// 比较你的外网IP网段判断
System.out.println(hosts[i].getHostAddress());
}
} catch( UnknownHostException e ) {
}
}
}