asp通过域名查IP
最近有个工作,知道了域名,把ip导出来,大约800多条记录,一个一个查麻烦了。有没有其他方法能让asp通过域名查IP呢?
在网上搜索了一下,asp通过域名查ip需要安装一个TCPIP.DNS的组件。我下载了一个测试了一下,效率并不是很高。
一般查询域名的ip的方法是ping一下,得到一个ip。我们先用VBScript测试。
Function strCut(strContent,StartStr,EndStr,CutType)
Dim strHtml,S1,S2
strHtml = strContent
On Error Resume Next
Select Case CutType
Case 1
S1 = InStr(strHtml,StartStr)
S2 = InStr(S1,strHtml,EndStr)+Len(EndStr)
Case 2
S1 = InStr(strHtml,StartStr)+Len(StartStr)
S2 = InStr(S1,strHtml,EndStr)
End Select
If Err Then
strCute = "0.0.0.0"
Err.Clear
Exit Function
Else
strCut = Mid(strHtml,S1,S2-S1)
End If
End Function
Function getIP(Domain)
Set objWShell=CreateObject("WScript.Shell")
Set objCmd=objWShell.Exec("ping "&Domain)
StrPResult=objCmd.StdOut.Readall()
Set objCmd=nothing
Set objWShell=nothing
getIP=strCut(StrPResult,"[","]",2)
End Function
startTme=timer
Wscript.echo getIP("www.baidu.com")
wscript.echo timer-startTme
不过效率很低哦,大约三秒钟的时间才能得到结果。通过域名查ip还有一个快速的方法,nslookup,我们修改一下上边的函数:
Function strCut(strContent)
ipsta=1
strLineArr=split(strContent,vbCrlf)
for each strLine in strLineArr
if instr(strLine,":")>0 then
getArr=split(strLine,":")
if LCase(getArr(0))="address" then
ipsta=1
end if
if ipsta=1 then
if LCase(getArr(0))="address" then
strCut=split(Trim(getArr(1)),",")(0)
exit function
end if
end if
end if
next
strCut="err"
End Function
Function getIP(Domain)
Set objWShell=CreateObject("WScript.Shell")
Set objCmd=objWShell.Exec("nslookup "&Domain)
StrPResult=objCmd.StdOut.Readall()
Set objCmd=nothing
Set objWShell=nothing
getIP=strCut(StrPResult)
End Function
startTme=timer
Wscript.echo getIP("www.baidu.com")
wscript.echo timer-startTme
现在速度快了,0.3秒即可搞定。vbscript是解决了,那asp通过域名查ip还是不可以的,一个最大的问题是虚拟主机一般都不给执行asp脚本运行WScript.Shell的权限,所以虚拟主机用户可以不用考虑了,TCPIP.DNS这种空间商肯定是不给用的。第二个问题也是安全问题,自己用的服务器,一般都不给web用户访问系统目录的权限,asp访问nslookup.exe的权限一般都没有?解决方法就是修改一下相关文件的权限即可。
< %
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")
%>