我不太確定如何獲取機器的外部IP地址,因爲網絡外的計算機會看到它。在Java中獲取'外部'IP地址
我的下列IPAddress類只獲取本機的本地IP地址。
public class IPAddress {
private InetAddress thisIp;
private String thisIpAddress;
private void setIpAdd() {
try {
InetAddress thisIp = InetAddress.getLocalHost();
thisIpAddress = thisIp.getHostAddress().toString();
} catch (Exception e) {
}
}
protected String getIpAddress() {
setIpAdd();
return thisIpAddress;
}
}
您知道一臺機器可以同時擁有多個公共地址嗎?它們確實與網絡接口相關,而不是機器。 – 2010-05-30 15:32:08