<%
Class Search
Private XMLHTTP
Private Sub Class_Initialize()
Set XMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
End Sub
Public Function GetCityByIP(IP)
DIM HTML , s , m , n , str2
If Trim(IP) = "" then
GetCityByIP= ""
Else
HTML = SendMessage("
http://www.ip138.com/ips8.asp" , "ip=" & IP & "&action=2")
s = instr(HTML , "本站主数据:")
m = instr(s , HTML , "</li>")
str2 = mid(HTML , s + len(s) + 2 , m - s - len(s) - 2)
GetCityByIP = str2
End If
End Function
Public Function GetCityByMobile(Mobile)
DIM HTML , s , m , n , str1 , str1Len , str2
If Trim(Mobile) = "" then
GetCityByMobile= ""
Else
HTML = SendMessage("
http://www.ip138.com:8080/search.asp" , "Mobile="&Mobile&"&action=mobile")
s = instr(HTML , "<TD width=""130"" align=""center"" noswap>卡号归属地</TD>")
str1 = "<TD width=* align=""center"" class=tdc2>"
str1Len = len(str1)
m = instr(s,HTML , str1)
n = instr(m , HTML , "</TD>")
str2 = Mid(HTML , m + str1Len , n - m - str1Len)
GetCityByMobile = str2
End if
End Function
Private Function SendMessage(URL , Data)
'XMLHTTP.onreadystatechange = getref("doHttpReadyStateChange")
Session.CodePage = 936
Response.Charset = "GB2312"
Response.C
XMLHTTP.open "POST", URL , false
Call XMLHTTP.setRequestHeader("charset","gb2312")
Call XMLHTTP.setRequestHeader("content-type","application/x-www-form-urlencoded")
XMLHTTP.Send(Data)
SendMessage = bytes2BSTR(XMLHTTP.responseBody)
End Function
Private Function bytes2BSTR(arrBytes)
strReturn = ""
arrBytes = CStr(arrBytes)
For i = 1 To LenB(arrBytes)
ThisCharCode = AscB(MidB(arrBytes, i, 1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(arrBytes, i+1, 1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
End Class
%>
应用方法
<%
DIM Address1 , Address2
Set S = new Search
Address1 = S.GetCityByMobile("13665210478") '调用Search类的GetCityByMobile方法 通过
Address2 = S.GetCityByIP("61.129.81.78") '调用Search类的GetCityByIP方法
%>