宛若重生
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";
}
}
好久没有分享了,最近做了这方面的东西,学习一下。
由最代码官方编辑于2017-2-15 10:00:16
猜你喜欢
请下载代码后再发表评论
相关代码
最近下载
最近浏览
疯子庭 LV8
2024年5月27日
微信网友_6669189563338752
2023年9月28日
暂无贡献等级
微信网友_6074338589790208
2022年8月4日
暂无贡献等级
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日





