您的位置:首页 > 编程语言 > ASP

asp根据ip得到地址信息

2014-11-21 17:14 302 查看
<%
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
%>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: