的事情是有一個像我的IP沒有這樣的事情。你的機器可以有多個接口,每個接口可以有多個IP。所以我真的不認爲你想進入它。您所能做的就是嘗試使用Web API來獲取您的外部IP地址。這是在Java代碼實際上只是這些網站的幫助
public static String getIpAddress()
{
URL myIP;
try {
myIP = new URL("http://api.externalip.net/ip/");
BufferedReader in = new BufferedReader(
new InputStreamReader(myIP.openStream())
);
return in.readLine();
} catch (Exception e)
{
try
{
myIP = new URL("http://myip.dnsomatic.com/");
BufferedReader in = new BufferedReader(
new InputStreamReader(myIP.openStream())
);
return in.readLine();
} catch (Exception e1)
{
try {
myIP = new URL("http://icanhazip.com/");
BufferedReader in = new BufferedReader(
new InputStreamReader(myIP.openStream())
);
return in.readLine();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
return null;
}
現在有了這個
,你可以從互聯網上獲得你的IP,但是又是你的外部IP
尋找你的IP互聯網上你可能想要查看http://stackoverflow.com/questions/8083479/java-getting-my-ip-address或http://stackoverflow.com/questions/9481865/how-to-get-ip-address-我們自己的系統使用java –
你是什麼意思的更好?更快,更可靠?最好的方式不會涉及硒 –
謝謝你的答覆。我只用硒因爲我不知道其他方式。有沒有其他方法? –