宛若重生的gravatar头像
宛若重生 2014-07-09 21:34:20

java获取本机的外网ip

public static String getWebIp() {
		  try {

		   URL url = new URL("http://iframe.ip138.com/ic.asp");

		   BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));

		   String s = "";

		   StringBuffer sb = new StringBuffer("");
		   
		   String webContent = "";

		   while ((s = br.readLine()) != null) {
		    sb.append(s + "\r\n");

		   }

		   br.close();
		   webContent = sb.toString();
		   int start = webContent.indexOf("[")+1;
		   int end = webContent.indexOf("]");
		   webContent = webContent.substring(start,end);
		   
		   return webContent;

		  } catch (Exception e) {
		   e.printStackTrace();
		   return "error";

		  }
	}

java获取本机的外网ip

好久没有分享了,最近做了这方面的东西,学习一下。


最代码官方编辑于2017-2-15 10:00:16


打赏

最代码最近下载分享源代码列表最近下载
最代码最近浏览分享源代码列表最近浏览
暂无贡献等级
暂无贡献等级
xingbing  LV9 2022年1月29日
zjh2019  LV18 2021年9月22日
最强之神  LV7 2021年7月4日
junq-G  LV2 2021年5月26日
谢LING  LV1 2021年3月10日
jiong521968  LV1 2020年11月28日
导出报表  LV8 2020年10月10日
a3318657232 2020年9月20日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友