java获取本机的外网ip

来源:互联网 发布:kindle软件下载 编辑:程序博客网 时间:2024/05/21 15:39

原文:java获取本机的外网ip

源代码下载地址:http://www.zuidaima.com/share/1901820081638400.htm

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";  }}

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

0 0
原创粉丝点击