IP query Interface address library and its simple use method

Source: Internet
Author: User
Tags format empty getscript interface json query return
Here to share a few of the current can be used, we need.

First, Taobao IP address library

*. URL: http://ip.taobao.com/

*. Request interface (GET): Http://ip.taobao.com/service/getipinfo.php?ip=[ip address]

*. Returns the data format: (JSON-formatted) country, province (autonomous region or municipality), city (county), operator. For example:

{"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 ":" The "," area_id ":" 100000 "," region_id ":" 110000 "," city_id ":" 110000 ",
" county_id ":" 1 "," isp_id ":" 100017 "}}

Note: The meaning of the code value is 0: success, 1: failure.

*. Taobao IP interface using the sample PHP version:

<?php
$ip =get_ip_data ();
function Get_ip_data () {
	$ip =file_get_contents ("http://ip.taobao.com/service/getIpInfo.php?ip="). Get_client_ IP ());
	$ip = Json_decode ($IP);
	if ($ip->code) {return
		false;
	}
	$data = (array) $ip->data;
	Print_r ($data);//return $data;
}

Take client IP
function get_client_ip () {
	if (isset ($_server[' http_client_ip ')) and!empty ($_server[' http_ Client_ip ']) {return
		$_server[' http_client_ip '];
	}
	if (Isset ($_server[' http_x_forwarded_for ')) and!empty ($_server[' http_x_forwarded_for ')) {return
		strtok ($_ server[' http_x_forwarded_for '], ', ');
	if (Isset ($_server[' Http_proxy_user ')) and!empty ($_server[' Http_proxy_user '))} {return
		$_server[' Http_proxy_ USER '];
	}
	if (Isset ($_server[' REMOTE_ADDR ')) and!empty ($_server[' remote_addr ')) {return
		$_server[' remote_addr '];
	} else {return
		' 0.0.0.0 ';
	}
}
? >

Second, Sina IP address query interface

*. Request interface (GET): Http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=[ip address]

Note: Parameter format can be set to return format: Js/json parameter ip optional query IP;

*. The return format is as follows:

var remote_ip_info = {"ret": 1, "Start": "125.40.0.0", "End": "125.40.111.255", "Country": "\u4e2d\u56fd", "province": "\ u6cb3\u5357 "," City ":" \u90d1\u5dde "," District ":" "," ISP ":" \u8054\u901a "," type ":" "," desc ":" "};

The following example uses the Getscript () method under jquery:

 <div id= "Sina_ip_info" ></div> <script src= "Http://code.jquery.com/jquery-1.7.2.min.js"
Text/javascript "></script> <script type=" Text/javascript "> var uip = ' 8.8.8.8 '; $.getscript (' http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip= ' +uip, function (_result) {var Ipdata = "";
		Initializes the Save content variable if (Remote_ip_info.ret = = ' 1 ') {ipdata = = "IP detail:<br>";
		Ipdata + + "IP:" + uip + "<br>";
		Ipdata + = "Country:" + remote_ip_info.country + "<br>";
		Ipdata + = "province:" + remote_ip_info.province + "<br>";
		Ipdata + = "City:" + remote_ip_info.city + "<br>";
		Ipdata + = "District:" + remote_ip_info.district + "<br>";
		Ipdata + + "ISP:" + remote_ip_info.isp + "<br>";
		Ipdata + = "type:" + Remote_ip_info.type + "<br>";
		Ipdata + = "Other:" + Remote_ip_info.desc + "<br>"; $ ("#sina_ip_info"). HTML (ipdata); Show processed Data} else {alert (' Error ', ' No matching IP address information found!
	');
}
}); </script> 

Third, Sohu IP address query interface (default encoding GBK)

*. Request interface (GET): Http://pv.sohu.com/cityjson?ie=utf-8

Iv. Pacific IP Address Library API interface

*. Request interface (GET): Http://whois.pconline.com.cn/?ip=[ip address string]

The invocation method is very rich and offers a variety of JS embedded calls.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.