Reverse DNS Lookups with DOS and ASP

Created 15 November 2002 00:00

DOS

nslookup <ip_address>

ASP

You need Windows Script Host 2.0 or higher installed in order to do this, but on a Windows NT or Windows 2000 machine you can perform reverse DNS lookups using the following code:
  Dim oFs
  Dim oShell 
  Dim oStream
  Dim temp 
  Dim sHost
  sHost = Request.Form("sHost")
  ' create shell object
  Set oShell = Server.CreateObject("Wscript.Shell")
  ' run NSLookup via command prompt
  oShell.Run "%ComSpec% /c nslookup " & sHost & "> C:" & sHost & ".txt", 0, True

  ' open the temp text file and write the contents to your page
  Set oFS = Server.CreateObject("Scripting.FileSystemObject")
  Set oStream = oFS.OpenTextFile("C:" & sHost & ".txt")

  Do While Not oStream.AtEndOfStream
    Response.Write "<br>" & Trim(oStream.Readline)
  Loop
  
  ' clean up    
  oStream.Close
  oFS.DeleteFile "C:" & sHost & ".txt"
  Set oFS = Nothing