ASP Code

Perform an NSLookup From an ASP Page

This subroutine will perform an nslookup of a server based on an IP address, and output the returned data to a text file. It will then parse the text file (using FileSystemObject), and output the information to the user's browser. The text file is then deleted.

By default the function looks up the user, by getting the browser's IP address (Request.ServerVariables("REMOTE_ADDR")). You can change this to whatever you want, or even specify the host string as a parameter.

Sub Lookup()
    strHost = Request.ServerVariables("REMOTE_ADDR")
    Set oShell = Server.CreateObject("Wscript.Shell")
    oShell.Run "%ComSpec% /c nslookup " & strHost & ">C:\" & strHost & ".txt",0,true
    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
                  tempData = tempData & Data & "<BR>"
            End IF
        i = (i + 1)
        oFS.DeleteFile "C:\" & strHost & ".txt"

    Set oFS = Nothing
    response.write  tempData
end sub

Leave a Reply

Your email address will not be published. Required fields are marked *

To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image