Hostip.info

1.返回HTM格式的数据

http://api.hostip.info/get_html.php?ip=118.123.13.254&position=true

返回数据示例:

Country: CHINA (CN)
City: Chengdu

Latitude: 30.65
Longitude: 104.067
IP: 118.123.13.254

2.返回XML文件 

http://api.hostip.info/?ip=118.123.13.254&position=true

返回数据示例:


<?xml version="1.0" encoding="ISO-8859-1" ?>
<HostipLookupResultSet version="1.0.1"
	xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="http://www.hostip.info/api/hostip-1.0.1.xsd">
	<gml:description>This is the Hostip Lookup Service</gml:description>
	<gml:name>hostip</gml:name>
	<gml:boundedBy>
		<gml:Null>inapplicable</gml:Null>
	</gml:boundedBy>
	<gml:featureMember>
		<Hostip>
			<ip>118.123.13.254</ip>
			<gml:name>Chengdu</gml:name>
			<countryName>CHINA</countryName>
			<countryAbbrev>CN</countryAbbrev>
			<!-- Co-ordinates are available as lng,lat -->
			<ipLocation>
				<gml:pointProperty>
					<gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
						<gml:coordinates>104.067,30.65</gml:coordinates>
					</gml:Point>
				</gml:pointProperty>
			</ipLocation>
		</Hostip>
	</gml:featureMember>
</HostipLookupResultSet>

3.返回所在国家或地图的旗帜

http://api.hostip.info/flag.php?ip=118.123.13.254


MaxMind(JavaScript接口)

获取访客IP地理位置信息

示例:

引入js文件

<script type="text/javascript" src="http://j.maxmind.com/app/geoip.js"></script>
该js的内容示例(注:笔者在浙江杭州)
function geoip_country_code() { return 'CN'; }
function geoip_country_name() { return 'China'; }
function geoip_city() { return 'Hangzhou'; }
function geoip_region() { return '02'; }
function geoip_region_name() { return 'Zhejiang'; }
function geoip_latitude() { return '30.2936'; }
function geoip_longitude() { return '120.1614'; }
function geoip_postal_code() { return ''; }
function geoip_area_code() { return ''; }
function geoip_metro_code() { return ''; } 


淘宝API

http://ip.taobao.com/service/getIpInfo.php?ip=118.123.13.254返回json数组

返回json数据示例如下:


{"code":0,"data":{"country":"u4e2du56fd","country_id":"86","area":"u897fu5357","area_id":"500000","region":"u56dbu5dddu7701","region_id":"510000","city":"u7ef5u9633u5e02","city_id":"510700","county":"","county_id":"-1","isp":"u7535u4fe1","isp_id":"100017","ip":"118.123.13.254"}}


利用php json_decode()后得到如下对象:(注:测试IP为本站IP,西部数据虚拟服务器,服务器位置在四川)


stdClass Object
(
    [code] => 0
    [data] => stdClass Object
        (
            [country] => 中国
            [country_id] => 86
            [area] => 西南
            [area_id] => 500000
            [region] => 四川省
            [region_id] => 510000
            [city] => 绵阳市
            [city_id] => 510700
            [county] => 
            [county_id] => -1
            [isp] => 电信
            [isp_id] => 100017
            [ip] => 118.123.13.254
        )

)