標籤:ip
話不多說,直接貼代碼!
將這段代碼運行一下就OK了:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>根據IP地址擷取所在城市</title>
<scriptsrc="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js"type="text/ecmascript"></script>
<script type="text/javascript">
function getIpPlace() {
alert(remote_ip_info["province"] + "省" + ‘,‘ +remote_ip_info["city"] + "市")
} </script>
</head>
<body>
<form id="form1"runat="server">
<div>
<input id="Button1" type="button"value="根據IP地址擷取所在城市" onclick="getIpPlace();"/>
</div>
</form>
</body>
</html>
所用介面:
http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js
返回結果:
var remote_ip_info = {"ret":1,"start":"1.192.0.0","end":"1.193.127.255","country":"\u4e2d\u56fd","province":"\u6cb3\u5357","city":"\u90d1\u5dde","district":"","isp":"\u7535\u4fe1","type":"","desc":""};
country:國家
province:省份
city:城市
isp:所用網路(例如電信)
js通過IP地址擷取所在城市