我正在尝试读取来自 isp 的非本地设备 IP 地址。
如何从代码中获取设备的 IP 地址?在这个检查过的答案中,我给出了 WI-FI 的 LAN IP 地址,并给出了与蜂窝互联网上的 whatismyip 不同的 IP 地址。我猜它可能是运营商服务提供商的本地IP。
我如何才能上网 IP 地址返回 whatismyip 的内容?
public static String getPublicIP() throws IOException
{
Document doc = Jsoup.connect("http://www.checkip.org").get();
return doc.getElementById("yourip").select("h1").first().select("span").text();
}
这个可能有用,但我不想为此添加任何库。
smallBig 编辑: http ://api.exip.org/?call= ip 它只返回 ip,我该如何使用它?它可靠且寿命长吗?