asp如何编写一个DNS LOOKUP程序?
来源:asp之家 时间:2009-11-07 18:47:00
首先安装WSH,NT(SERVER、WORKSTATION)、W2K服务器上需要安装WSH2.0或者更高版本。
然后,参照下列代码即可:
<%@ Language="VBScript" %>
<% Option Explicit %>
<%
If Request.Form("frmHost") = "" Then
' 设置初始值
strIP = Request.ServerVariables("REMOTE_ADDR")
Else
strIP = Request.Form("frmHost")
End If
%>
<html>
<head>
<title>精彩春风之DNS 浏览</title>
</head>
<body bgcolor="#FFFFFF">
<form Method="POST" Name="frmRDNS">
<label for="frmHost"><u>主机:</u></label>
<input type="text" name="frmHost" ID="frmHost"
value="<%= strIP %>">
<input type="button" name="btnSubmit" ID="btnSubmit"
value="浏览" onClick="document.frmRDNS.submit()">
</form>
<font face="arial" size="2" color="#003366">
<%
rMethod = uCase(Request.ServerVariables("REQUEST_METHOD"))
If rMethod = "POST" Then
' 浏览主机
strReturn = nsLookup(strIP)
If strReturn <> "" Then
Response.Write strReturn
Else
Response.Write "<b>抱歉,这台主机不能解析" _ & strIP & " DNS </b><br>"
End If
End If
Function NSlookup(strHost)
' 创建Shell对象
Set oShell = Server.CreateObject("Wscript.Shell")
oShell.Run "%ComSpec% /c nslookup " & strHost _
& "> C:\" & strHost & ".txt", 0, True
' 通过命令提示符执行 NSLookup,并将结果转存到临时文本文件中
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
Set oTF = oFS.OpenTextFile("C:\" & strHost & ".txt")
'打开临时文本文件读取数据
tempData = Null
Data = Null
i = 0
Do While Not oTF.AtEndOfStream
Data = Trim(oTF.Readline)
If i > 2 Then ' Don't want to display local DNS Info.
tempData = tempData & Data & "<BR>"
End If
i = (i + 1)
Loop
oTF.Close
' 关闭
oFS.DeleteFile "C:\" & strHost & ".txt"
' 删除之
Set oFS = Nothing
nsLookup = tempData
End Function
%>
</font>
</body>
</html>