1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 获取本机外网ip地址

获取本机外网ip地址

时间:2019-12-30 04:02:43

相关推荐

获取本机外网ip地址

package com.ning;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import .URL;

public class Listip {

public static void main(String[] args) throws Exception {

System.out.println("本机的外网IP是:"

//+ Listip.getWebIp("/ic.asp"));

//+ Listip.getWebIp(""));

+ Listip.getWebIp("/ic.asp"));

}

public static String getWebIp(String strUrl) {

try {

URL url = new URL(strUrl);

BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(),"GB2312"));

String s = "";

StringBuffer sb = new StringBuffer("");

String webContent = "";

while ((s = br.readLine()) != null) {

sb.append(s + "rn");

}

br.close();

webContent = sb.toString();

int start = webContent.indexOf("[") + 1;

int end = webContent.indexOf("]");

System.out.println("webContent=" + webContent);

System.out.println("start=" + start);

System.out.println("end=" + end);

if (start < 0 || end < 0) {

return null;

}

webContent = webContent.substring(start, end);

return webContent;

} catch (Exception e) {

e.printStackTrace();

return "error open url:" + strUrl;

}

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。