有时需要获取远程网站的某些信息,而服务器又限制了GET方式,只能通过POST数据提交,这个时候我们可以通过asp来实现模拟提交post数据,飘易加工了下面的部分代码,比如获取IP138的IP数据地址信息,代码如下:
<%
On error resume next '容错处理
Function GetBody(ips) '飘易-获取远程IP地址POST信息
Set https = Server.CreateObject("MSXML2.XMLHTTP")
With https
.Open "Post", "http://www.ip138.com/ips8.asp", False
.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
.Send "ip="&ips&"&action=2"
GetBody = .ResponseBody
End With
GetBody = BytesToBstr(GetBody,"GB2312")
Set https = Nothing
End Function
Function BytesToBstr(body,Cset) '飘易:转换GB2312
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
Response.Write GetBody("61.186.177.105")
%>
关于
屏蔽异地IP的方法,可以参考这个链接。
PS:(2010年3月30号更新)
由于IP138采用了防CC攻击的防火墙,所以现在的这种调用远程IP138页面来判断IP的方法已经不行了。因为程序打开
http://www.ip138.com/ips8.asp 页面的时候,服务器自动响应成 http://www.ip138.com/ips8.asp?jdfwkey=p7akv1 这样的url。从而导致出现 错误:“msxml3.dll 错误 '800c0008' 指定资源下载失败”,无法获取正确的源码。
但是,我们别忘了IP138也和百度合作,这就是 百度搜索开放平台:
http://open.baidu.com/,这里就有IP138查询IP的功能:比如
http://open.baidu.com/ipsearch/s?wd=59.61.160.237&tn=baiduip 。