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

你可能感兴趣的:(java,ip)