asp根据ip得到地址信息

<%
response.write getAddrByIp("220.160.203.142")

'根据ip得到地址的函数
Function getAddrByIp(ByVal strIP)
	'采集页面代码
    Set XmlHttp = CreateObject("Microsoft.XMLHTTP")
    XmlHttp.Open "GET", "http://www.baidu.com/s?wd=" & strIP, False
    XmlHttp.send
    Set objStream = CreateObject("Adodb.Stream")
    objStream.Type = 1
    objStream.Mode = 3
    objStream.Open
    objStream.Write XmlHttp.ResponseBody
    objStream.position = 0
    objStream.Type = 2
    objStream.Charset = "UTF-8"
    strData = objStream.ReadText
    objStream.Close
    Set objStream = Nothing
    Set XmlHttp = Nothing
	
	'正则匹配得到地址信息
    Set reg = CreateObject("vbscript.regExp")
    reg.Global = True
    reg.IgnoreCase = True
    reg.MultiLine = True
    reg.Pattern = strIP & "</span>(.+)"
    Set matchs = reg.Execute(strData)
    For Each match In matchs
        getAddrByIp = match.SubMatches(0)
    Next
End Function
%>

展开阅读全文

没有更多推荐了,返回首页