ASP 101 - Active Server Pages 101 - Web04
The Place ASP Developers Go!

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
What is ASP?
VBScript Classes: Part 1 of N
Migrating to ASP.NET

Apply Master Pages By Folder
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

ASP Based Reverse DNS Lookup

ASP Based Reverse DNS Lookup

by Jason Withrow

Many people fail to realize the full power of ASP. You don't need components for everything. ASP can be utilized for many things people never knew it could be.

So, as an example of this, I wrote this script to perform a reverse DNS Lookup, and did it in about 5 minutes.

There are some requirements to using this script. It will only run on a Windows NT (Server or Workstation) or Windows2000 (Server or Professional) box, and you must have Windows Script Host (WSH) 2.0 or higher installed.

If you don't already have it, you can download Windows Script 5.5 (which includes WSH 2.0) for free from Microsoft at

<%@ Language="VBScript" %>
<% Option Explicit %>
If Request.Form("frmHost") = "" Then
    ' Set Initial Value to Local IP Address
    strIP = Request.ServerVariables("REMOTE_ADDR")
    strIP = Request.Form("frmHost") 
End If
    <title>Jay's ASP Reverse DNS Lookup [v 1.0]</title>
<body bgcolor="#FFFFFF">
<form Method="POST" Name="frmRDNS">
    <label for="frmHost"><u>Host:</u></label>
    <input type="text" name="frmHost" ID="frmHost"
        value="<%= strIP  %>">
    <input type="button" name="btnSubmit" ID="btnSubmit"
        value="Lookup" onClick="document.frmRDNS.submit()">
<font face="arial" size="2" color="#003366">
rMethod = uCase(Request.ServerVariables("REQUEST_METHOD"))
If rMethod = "POST" Then
    ' Lookup Host
    strReturn = nsLookup(strIP)
    If strReturn <> "" Then
        Response.Write strReturn
        ' 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 " _
            & strIP & "</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 " & strHost _
        & "> C:\" & strHost & ".txt", 0, True
    'Open the temp Text File and Read out the Data
    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)
    'Close it
    'Delete It
    oFS.DeleteFile "C:\" & strHost & ".txt"
    Set oFS = Nothing
    nsLookup = tempData
End Function

That's all there is to it! You see... you really can do it in ASP! You can download the zipped file or follow along and write it yourself.

Regards, - Jason Withrow

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers