java獲取公網ip代碼

 private static String getInternetIp() throws Exception{
    	try {
            // 打開連接
            Document doc = Jsoup.connect("http://chaipip.com/").get();
            Elements eles = doc.select("#ip");
            return eles.attr("value");
        }catch (IOException e) {
            e.printStackTrace();            
        }
       
        return InetAddress.getLocalHost().getHostAddress();  	
    }

公網ip轉城市用ip2Region,附上鍊接:

https://gitee.com/lionsoul/ip2region

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章