用ASP做的DNS LOOKUP程序

文章转译自ASP101

运行环境,NT(SERVER、WORKSTATION)、W2K

服务器上需要安装WSH2.0或者更高版本

如果您的系统目前没有安装WSH2.0,您可以从以下这个地址去下载它

http://www.microsoft.com/msdownload/vbscript/scripting.asp

里面包含了WSH2.0

下面是源代码

1@ Language="VBScript" 
1 Option Explicit 
1   
2If Request.Form("frmHost") = "" Then   
3'设置初始值   
4strIP = Request.ServerVariables("REMOTE_ADDR")   
5Else   
6strIP = Request.Form("frmHost")   
7End If   
 1<html>
 2<head>
 3<title>DNS Lookup [v 1.0]</title>
 4</head>
 5<body bgcolor="#FFFFFF">
 6<form method="POST" name="frmRDNS">
 7<label for="frmHost"><u>Host:</u></label>
 8<input id="frmHost" name="frmHost" type="text" value="```
 9= strIP 
10```"/>
11<input id="btnSubmit" name="btnSubmit" onclick="document.frmRDNS.submit()" type="button" value="Lookup"/>
12</form>
13<font color="#003366" face="arial" size="2">   

rMethod = uCase(Request.ServerVariables("REQUEST_METHOD"))
If rMethod = "POST" Then
' Lookup Host
strReturn = nsLookup(strIP)
If strReturn &lt;&gt; "" Then
Response.Write strReturn
Else
' A Lame Host is any Valid Host that DNS Cannot Resolve
' See InterNic for Details
Response.Write "<b>Lame Host - Could Not Resolve DNS For " _
&amp; strIP &amp; "</b><br/>"
End If
End If

Function NSlookup(strHost)
'Create Shell Object
Set oShell = Server.CreateObject("Wscript.Shell")
'Run NSLookup via Command Prompt
'Dump Results into a temp text file
oShell.Run "%ComSpec% /c nslookup " &amp; strHost _
&amp; "&gt; C:" &amp; strHost &amp; ".txt", 0, True

'Open the temp Text File and Read out the Data
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
Set oTF = oFS.OpenTextFile("C:" &amp; strHost &amp; ".txt")

tempData = Null
Data = Null
i = 0
Do While Not oTF.AtEndOfStream
Data = Trim(oTF.Readline)
If i &gt; 2 Then ' Don't want to display local DNS Info.
tempData = tempData &amp; Data &amp; "<br/>"
End If
i = (i + 1)
Loop

'Close it
oTF.Close
'Delete It
oFS.DeleteFile "C:" &amp; strHost &amp; ".txt"

Set oFS = Nothing
nsLookup = tempData
End Function

1</font>
2</body>
3</html>

代码很简单,我不多说了,如果您对WSH有什么疑问的话,请去下载WSH的电子文档中文版本的,CHINAASP下载区就有的吧

希望能对你有所帮助。

Published At
Categories with Web编程
Tagged with
comments powered by Disqus