怎么取公网的IP地址?
写了个程序,就是只能取出局域网的IP,郁闷呀,那位大哥帮帮忙?小弟先谢过了!!
import java.net.InetAddress;
public class IP {
public static void main (String[] args)throws Exception {
InetAddress address=InetAddress.getLocalHost();
String hostName=address.getHostName();
System.out.println("HostName:"+hostName);
InetAddress addresses[]=InetAddress.getAllByName(hostName);
for(int i=0;i<addresses.length;i++){
System.out.println("hostAddress"+i+":"+addresses[i].getHostAddress());
}
}
}