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 }
  • 相关阅读:
    将log4Net记录的日志导入数据库操作指南
    算法40 leetcode 155.最小栈
    c++求以3为底的对数 遇到243 怎么也通不过
    算法36 动规初探&&斐波那契&&尾递归
    算法38 5. 最长回文子串
    算法39 leetcode22. 括号生成
    算法34 堆排序heapsort
    算法37 动规求数组和
    算法35 力扣twosum
    c++ vector size()18446744073709551615 bug
  • 原文地址:https://www.cnblogs.com/wmh1997/p/11006507.html
Copyright © 2011-2022 走看看