1. 程式人生 > >java根據ip地址獲取詳細地域資訊

java根據ip地址獲取詳細地域資訊

網際網路有很多介面可以實現通過ip查詢到具體的位置,如下:

通過淘寶IP地址庫獲取IP位置

1. 請求介面(GET):http://ip.taobao.com/service/getIpInfo.php?ip=[ip地址字串] 2. 響應資訊:(json格式的)國家 、省(自治區或直轄市)、市(縣)、運營商 3. 返回資料格式: {"code":0,"data":{"ip":"210.75.225.254","country":"\u4e2d\u56fd","area":"\u534e\u5317", "region":"\u5317\u4eac\u5e02","city":"\u5317\u4eac\u5e02","county":"","isp":"\u7535\u4fe1", "country_id":"86","area_id":"100000","region_id":"110000","city_id":"110000", "county_id":"-1","isp_id":"100017"}} 其中code的值的含義為,0:成功,1:失敗。  新浪的介面 :http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=218.192.3.42 返回值 var remote_ip_info = {"ret":1,"start":"218.192.0.0","end":"218.192.7.255","country":"\u4e2d\u56fd","province":"\u5e7f\u4e1c","city":"\u5e7f\u5dde","district":"","isp":"\u6559\u80b2\u7f51","type":"\u5b66\u6821","desc":"\u5e7f\u5dde\u5927\u5b66\u7eba\u7ec7\u670d\u88c5\u5b66\u9662"}; 通過jqry 獲取相應的資料 $.getScript('資料介面',function(){ //新浪:remote_ip_info.country })  騰訊IP分享計劃的地址獲取IP所在地:

用java呼叫淘寶ip查詢介面查詢地域的一個java例項:

  1. import java.io.BufferedReader;  
  2. import java.io.DataOutputStream;  
  3. import java.io.IOException;  
  4. import java.io.InputStreamReader;  
  5. import java.io.UnsupportedEncodingException;  
  6. import java.net.HttpURLConnection;  
  7. import java.net.URL;  
  8. /** 
  9.  *  根據IP地址獲取詳細的地域資訊 
  10.  *  @project:personGocheck
     
  11.  *  @class:AddressUtils.java 
  12.  *  @author:heguanhua E-mail:[email protected] 
  13.  *  @date:Nov 14, 2012 6:38:25 PM 
  14.  */
  15. publicclass AddressUtils {   
  16.  /** 
  17.   * 
  18.   * @param content 
  19.   *            請求的引數 格式為:name=xxx&pwd=xxx 
  20.   * @param encoding 
  21.   *            伺服器端請求編碼。如GBK,UTF-8等 
  22.   * @return
     
  23.   * @throws UnsupportedEncodingException 
  24.   */
  25.  public String getAddresses(String content, String encodingString)  
  26.    throws UnsupportedEncodingException {  
  27.   // 這裡呼叫pconline的介面
  28.   String urlStr = "http://ip.taobao.com/service/getIpInfo.php";  
  29.   // 從http://whois.pconline.com.cn取得IP所在的省市區資訊
  30.   String returnStr = this.getResult(urlStr, content, encodingString);  
  31.   if (returnStr != null) {  
  32.    // 處理返回的省市區資訊
  33.    System.out.println(returnStr);  
  34.    String[] temp = returnStr.split(",");  
  35.    if(temp.length<3){  
  36.     return"0";//無效IP,區域網測試
  37.    }  
  38.    String region = (temp[5].split(":"))[1].replaceAll("\"""");  
  39.    region = decodeUnicode(region);// 省份
  40.             String country = "";  
  41.             String area = "";  
  42.             // String region = "";
  43.             String city = "";  
  44.             String county = "";  
  45.             String isp = "";  
  46.             for (int i = 0; i < temp.length; i++) {  
  47.                 switch (i) {  
  48.                 case1:  
  49.                     country = (temp[i].split(":"))[2].replaceAll("\"""");  
  50.                     country = decodeUnicode(country);// 國家
  51.                     break;  
  52.                     case3:  
  53.                         area = (temp[i].split(":"))[1].replaceAll("\"""");  
  54.                         area = decodeUnicode(area);// 地區 
  55.                     break;  
  56.                     case5:  
  57.                         region = (temp[i].split(":"))[1].replaceAll("\"""");  
  58.                         region = decodeUnicode(region);// 省份 
  59.                     break;   
  60.                     case7:  
  61.                         city = (temp[i].split(":"))[1].replaceAll("\"""");  
  62.                         city = decodeUnicode(city);// 市區
  63.                     break;   
  64.                     case9:  
  65.                             county = (temp[i].split(":"))[1].replaceAll("\"""");  
  66.                             county = decodeUnicode(county);// 地區 
  67. 相關推薦

    java根據ip地址獲取詳細地域資訊

    網際網路有很多介面可以實現通過ip查詢到具體的位置,如下: 通過淘寶IP地址庫獲取IP位置 1. 請求介面(GET):http://ip.taobao.com/service/getIpInfo.php?ip=[ip地址字串] 2. 響應資訊:(

    java 根據IP地址獲取地理位置

    1. 第三方API ps:下面引數ip:218.192.3.42 用於測試 淘寶API:http://ip.taobao.com/service/getIpInfo.php?ip=218.192.3.42 新浪API:http://int.dpool.sina.

    Java 根據 IP 地址獲取 位置 -- 使用 ip2region

    首先在 maven 裡面引入 ip2region : <dependency> <groupId>org.lionsoul</groupId> <artifactId>ip2region</artifactId&

    java實現根據ip地址獲取地理位置

    記錄學習使用,轉載地址:http://www.jb51.net/article/54287.htm 程式呼叫了“騰訊ip分享計劃”提供的介面,當然也可以改成ip138提供的介面,不過這兩個網站返回的字串格式有些不同,要分別做解析。 public String getAdd

    前端使用js根據ip地址獲取城市地理位置

                                      前端使用js根據ip地址獲取城市地理位置  

    根據ip地址獲取地理位置及座標

    根據ip獲取地理位置資訊,不用http和webservice介面,減少請求時間。我們可以利用了GeoLite2 庫,GeoLite2 資料庫是一個免費的 IP 地理定位資料庫,GeoLite2 Country 與 City 資料庫在每月的第一個週二更新。GeoLite2 AS

    Android 根據IP地址獲取城市

    manifest中要加的permission和activity_main.xml 參照上。 MainActivity.java package com.example.test; import java.util.List; import java.util.Loc

    根據ip地址獲取所在省市城市地區的真實地址/php函式

    /*獲取客戶端ip*/ function _get_ip(){ if (isset($_SERVER['HTTP_CLIENT_IP']) && strcasecmp($_SER

    PHP開發小技巧②③—根據ip地址獲取城市

            這個方法我們用的還是比較多的,便於收集資訊用於資料探勘分析。此方法不光根據ip地址進行獲取當前城市還可以根據http請求獲取使用者的城市位置。         實現方法:主要是根據高德地圖API進行獲取,首先註冊成為高德地圖使用者,然後認證成為開發者,建

    根據ip地址獲取城市

    <?php /** * Created by PhpStorm. * User: xym * Date: 2018/1/15 * Time: 下午1:57 */ function getIPLoc_sina($queryIP){ $url = 'http:/

    java 根據圖片地址獲取到圖片的大小,單位kb或者Mb

    /**       * byte(位元組)根據長度轉成kb(千位元組)和mb(兆位元組)       *        * @param bytes       * @return       */

    java 根據ip獲取地址

    try throw quest pin end china args 超時時間 con 用淘寶接口:(源碼:java 根據IP地址獲取地理位置) pom.xml: <!-- https://mvnrepository.com/artifact/net.sourcef

    獲取IP地址詳細信息——Java

    his lib rgs ace port finally NPU java.net try 代碼 import com.alibaba.fastjson.JSON; import java.io.BufferedReader; import java.io.InputS

    Java根據HttpServletRequest請求獲取伺服器的IP地址

      以下總結了兩種根據HttpServletRequest請求獲取發出請求瀏覽器客戶端所在伺服器的IP地址方法: 程式碼: import javax.servlet.http.HttpServletRequest; /** * 根據HttpServletRequest請求獲取發出請求瀏覽器客戶端

    Java根據HttpServletRequest請求獲取服務器的IP地址

    client -i 根據 請求 代碼 brush clas get tip   以下總結了兩種根據HttpServletRequest請求獲取發出請求瀏覽器客戶端所在服務器的IP地址方法: 代碼: import javax.servlet.http.HttpServlet

    根據ip地址和子網掩碼獲取廣播地址java實現

    /** * 獲取廣播地址 * */ public static String getBroadcastAddress(String subnet, String ip) { String[] ips = ip.split("\\."); String[]

    Java根據IP獲取國家省級地市信息

    object ringbuf from rgs buffere while except pro open package com.ust.map; import java.io.BufferedReader;import java.io.IOException;impor

    根據ip地址定位城市資訊

    最近需要一個需求就是根據ip地址獲取使用者的地址資訊,搜尋了網上的方法,有H5定位和呼叫web api介面定位. 相比之下H5要求瀏覽器支援,在移動裝置上可以實現呼叫手機gps獲取位置資訊,精確度很高。web api定位可以定位到城市,相對來說精確度不高,對比了百度,高德,淘寶,新浪的web a

    騰訊地圖逆地址解析,通過經緯度獲取詳細資訊資料

    根據騰訊地圖API,以圖文的方式一步一步的來說明如何獲取詳細的位置資訊資料。具體參考騰訊地圖Webservice API的簡介。騰訊地圖WebService API   第一步:申請開發者金鑰(key)申請金鑰       我選擇的應用型別為瀏覽器型別(呼叫Javascr

    通過ip地址獲取ip地址的區域資訊

    return $res1['data']["country"].$res1['data'][ "region"].$res1['data']["city"]."_".$res1['data'][ "isp"];