zoukankan      html  css  js  c++  java
  • java获取公网ip以及物理地址和代理商

     1 package ipconfig;
     2 
     3 import java.io.BufferedReader;
     4 import java.io.IOException;
     5 import java.io.InputStreamReader;
     6 import java.net.MalformedURLException;
     7 import java.net.URL;
     8 import java.net.URLConnection;
     9 
    10 public class gainInformation {
    11     public static void main(String args[]) {
    12         String publicip = getip.publicip();
    13         int ipindex1 = publicip.indexOf("[");
    14         int ipindex2 = publicip.indexOf("]");
    15         String ip = publicip.substring(ipindex1+1, ipindex2);
    16         System.out.println(ip);
    17         int address1 = publicip.indexOf("来自:");
    18         int address2 = publicip.indexOf("</center>");
    19         String substring = publicip.substring(address1+3,address2);
    20         String[] split = substring.split(" ");
    21         for (int i = 0; i < split.length; i++) {
    22             System.out.println(split[i]);
    23         }
    24     }
    25 }
    26     class getip{
    27     public static String publicip() {
    28         BufferedReader br = null;
    29         try {
    30             URL url = new URL("http://20019.ip138.com/ic.asp");
    31             URLConnection urlconn = url.openConnection();
    32             br = new BufferedReader(new InputStreamReader(urlconn.getInputStream()));
    33             String buf,get = null;
    34             while ((buf = br.readLine()) != null) {
    35                 get+=buf;
    36             }
    37             return get;
    38         } catch (MalformedURLException e) {
    39             e.printStackTrace();
    40         } catch (IOException e) {
    41             e.printStackTrace();
    42         } finally {
    43             try {
    44                 br.close();
    45             } catch (IOException e) {
    46                 e.printStackTrace();
    47             }
    48         }
    49         return null;
    50     }
    51 }
  • 相关阅读:
    MVC @Url.Action 小示例
    Eclipse快捷键
    MVC视频下载/文件上传
    MySQL数据库备份/导出
    C#文件下载
    C#正则表达式匹配字符串中的数字
    常用的LINQ to SQL 用法
    C# 实现抓取网页内容(一)
    C# 繁体字和简体字之间的相互转换
    我到底会什么??
  • 原文地址:https://www.cnblogs.com/wmh1997/p/11006507.html
Copyright © 2011-2022 走看看