您的位置:首页 > Web前端 > HTML

ASP函数 获取域名解析后的IP 获取远程网页的HTML代码

2013-01-15 23:30 691 查看
<%
'获取  域名解析后的IP
Function strCut(strContent)
strLineArr=split(strContent,vbCrlf)
for each strLine in strLineArr
if instr(strLine,":")>0 then
getArr=split(strLine,":")
if LCase(getArr(0))="addresses" then
strCut=split(Trim(getArr(1)),",")(0)
exit function
end if
end if
next
strCut="err"
End Function

Function getIP(Domain)
Set objWShell=Server.CreateObject("WScript.Shell")
Set objCmd=objWShell.Exec(server.mappath("nslookup.exe")&" "&Domain)
StrPResult=objCmd.StdOut.Readall()
Set objCmd=nothing
Set objWShell=nothing
getIP=strCut(StrPResult)
End Function

response.write getIP("www.baidu.com")
%>


<%
'获取远程网页的HTML代码
Function getHTTPPage(url)
On Error Resume Next
dim http
set http=Server.createobject("Microsoft.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
If Err.number<>0 then
Response.Write "<p align='center'><font color='red'><b>服务器获取文件内容出错</b></font></p>"
Err.Clear
End If
End Function

Function BytesToBstr(body,Cset)
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 getHTTPPage("http://www.baidu.com")
%>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: