• 新浪ip地址查询接口调用方面


     

    import com.cdeledu.plat.fin.common.util.URLUtil;
    import com.cdeledu.plat.fin.common.util.WebPage;
    import com.google.gson.Gson;
    import com.google.gson.JsonElement;
    import com.google.gson.JsonObject;
    import com.google.gson.JsonParser;

    public class IpLookUp
    {
     private static String sinaURL = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=";

     public static String sinaIpLookup(String ip)
     {
      String pageURL = sinaURL;
      WebPage webPage = null;
      String json = "";
      webPage = URLUtil.getPageContent(pageURL + ip);
      if(webPage != null && webPage.getHtml() != null)
      {
       json = webPage.getHtml();
       String begin = "{";
       String end = "}";
       json = json.substring(json.indexOf(begin), json.indexOf(end) + 1);
      }
      return json;
     }
     public static IpInfo parserSinaLoopkUpIpInfo(String json)
     {
      Gson gson = new Gson();
      IpInfo ipInfo = null;
      JsonParser parser = new JsonParser();
      JsonElement jsonElement = parser.parse(json);
      if(jsonElement.isJsonObject())
      {
       JsonObject JsonObject = (JsonObject)jsonElement;
       ipInfo = gson.fromJson(JsonObject, IpInfo.class);
       if(ipInfo != null)
       {
        System.out.println(ipInfo.getStart() + "\t" + ipInfo.getEnd() + "\t" + ipInfo.getProvince());
       }
      }
      return ipInfo;
     }
     /**
      * @param args
      */
     public static void main(String[] args)
     {
      String ip = "219.232.43.228";
      ip = "218.94.132.146";
      long start = System.currentTimeMillis();
      String json = sinaIpLookup(ip);
      IpInfo ipInfo = parserSinaLoopkUpIpInfo(json);
      System.out.println(ipInfo);
      System.out.println("===times===" + (System.currentTimeMillis() - start));
     }

  • 相关阅读:
    Java MQTT 客户端之 Paho
    Spring Security + JJWT 实现 JWT 认证和授权
    MinIO
    Spring Boot 实现看门狗功能 (调用 Shell 脚本)
    Canal Admin
    canal
    浅尝 Elastic Stack (五) Logstash + Beats + Kafka
    养鸡场下蛋记
    涛声依旧
    原创:矩阵论学习心得
  • 原文地址:https://www.cnblogs.com/something/p/3102062.html
Copyright © 2020-2023  润新知