<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%><%
'asp利用sina提供的ip库端口来获得当前IP所有的地区,所在国,所在省,所在市,在线解析json
this_ip = Request.ServerVariables("REMOTE_ADDR")
get_ip_url = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=" & g_ip
UserInfo=GetURL(get_ip_url)
Call InitScriptControl:Set objTest = getJSONObject(UserInfo)
response.write "当前IP:" & this_ip & "____<br>"
response.write "当前解析地址:" & get_ip_url & "____<br>"
response.write "获得的json内容:" & UserInfo & "____<br>"
response.write "解析IP所在国:" & objTest.country & "____<br>"
response.write "当前IP所在省:" & objTest.province & "____<br>"
response.write "当前IP所在市:" & objTest.city & "____<br>"
'解析json
'Call InitScriptControl
'Set objTest = getJSONObject(strTest)
Dim sc4Json
Sub InitScriptControl
Set sc4Json = Server.CreateObject("MSScriptControl.ScriptControl")
sc4Json.Language = "JavaScript"
sc4Json.AddCode "var itemTemp=null;function getJSArray(arr, index){itemTemp=arr[index];}"
End Sub
Function getJSONObject(strJSON)
sc4Json.AddCode "var jsonObject = " & strJSON
Set getJSONObject = sc4Json.CodeObject.jsonObject
End Function
Sub getJSArrayItem(objDest,objJSArray,index)
On Error Resume Next
sc4Json.Run "getJSArray",objJSArray, index
Set objDest = sc4Json.CodeObject.itemTemp
If Err.number=0 Then Exit Sub
objDest = sc4Json.CodeObject.itemTemp
End Sub
Dim scriptCtrl
Function parseJSON(str)
If Not IsObject(scriptCtrl) Then
Set scriptCtrl = Server.CreateObject("MSScriptControl.ScriptControl")
scriptCtrl.Language = "JavaScript"
scriptCtrl.AddCode "function ActiveXObject() {}" ' 覆盖 ActiveXObject
scriptCtrl.AddCode "function GetObject() {}" ' 覆盖 ActiveXObject
scriptCtrl.AddCode "Array.prototype.get = function(x) { return this[x]; }; var result = null;"
End If
On Error Resume Next
scriptCtrl.ExecuteStatement "var result = " & str & ";"
Set parseJSON = scriptCtrl.CodeObject.result
If Err Then
Err.Clear
Set parseJSON = Nothing
End If
End Function
'Get内容
Function GetURL(url)
dim http
set http=server.createobject("Msxml2.ServerXMLHTTP")
http.open "GET",url,false
http.setRequestHeader "If-Modified-Since","0"
http.send()
GetURL=http.responsetext
set http=nothing
End Function
%>