none
How to NSLookup an input in VBScript RRS feed

  • Question

  •  I'm trying to make a VBScript script to do an NSLookup of something typed in an inputbox and turn the result into a variable, as if it would be used in other functions.

     Is that possible?

    • Moved by Mark Liu-lxf Friday, July 6, 2012 5:29 AM (From:Visual Basic General)
    Thursday, July 5, 2012 1:31 PM

Answers

  • This example demonstrates how you can use the Exec method of the wshShell object to run a command and capture the output. This example parses the output for the IP address of a computer:

    Option Explicit
    Dim objshell, strCmd, objExec, strLine, strIP

    set objShell = CreateObject("Wscript.Shell")

    strCmd = "%comspec% /c nslookup MyComputer"
    Set objExec = objShell.Exec(strCmd)
    Do Until objExec.StdOut.AtEndOfStream
        strLine = objExec.StdOut.ReadLine()
        If (Left(strLine, 8) = "Address:") Then
            strIP = Trim(Mid(strLine, 9))
            Wscript.Echo strIP
        End If
    Loop

    -----



    Richard Mueller - MVP Directory Services

    Sunday, July 15, 2012 12:17 AM
    Moderator
  • [system.net.dns]::Resolve('technet.microsoft.com')
    [system.net.dns]::GetHostAddresses('technet.microsoft.com')
    [system.net.dns]::GetHostByAddress('127.0.0.1')
    [system.net.dns]::GetHostByName('www.msn.net')


    ¯\_(ツ)_/¯

    Sunday, July 15, 2012 9:41 PM

All replies

  • I would post your question to The Official Scripting Guys Forum!. This forum is primarily for Visual Basic .NET questions.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Proposed as answer by Mark Liu-lxf Friday, July 6, 2012 5:26 AM
    Thursday, July 5, 2012 2:07 PM
  •  I'm trying to make a VBScript script to do an NSLookup of something typed in an inputbox and turn the result into a variable, as if it would be used in other functions.

     Is that possible?

    Yes - what are you looking up?  NSLookup has many things to offer. IPs, DNS, MX, Contact, etc.


    ¯\_(ツ)_/¯

    Friday, July 6, 2012 9:37 AM
  • This example demonstrates how you can use the Exec method of the wshShell object to run a command and capture the output. This example parses the output for the IP address of a computer:

    Option Explicit
    Dim objshell, strCmd, objExec, strLine, strIP

    set objShell = CreateObject("Wscript.Shell")

    strCmd = "%comspec% /c nslookup MyComputer"
    Set objExec = objShell.Exec(strCmd)
    Do Until objExec.StdOut.AtEndOfStream
        strLine = objExec.StdOut.ReadLine()
        If (Left(strLine, 8) = "Address:") Then
            strIP = Trim(Mid(strLine, 9))
            Wscript.Echo strIP
        End If
    Loop

    -----



    Richard Mueller - MVP Directory Services

    Sunday, July 15, 2012 12:17 AM
    Moderator
  • Her is a subtle and sneaky way to do the same thing.

    dnsname = "google.com"
    Set wmi=GetObject("winmgmts:")
    Set response = wmi.ExecQuery(" Select * from Win32_PingStatus WHERE address='" & dnsname & "'")
    For each r in response
    	WScript.Echo "DNS Name:" & r.Address & " has addresses: " & r.ProtocolAddress
    Next

    No muss! No fuss!

    If you need MX, ADMIN, TXT or other doamin records then you will have to learn how to interactivly drive NSLOOKUP as above.  Tha this why I asked what was required.

    We seldom need to use NSLOOKUP because PING does a lookup for us and tests the 'lieveness' of the target, and, all in one step.


    ¯\_(ツ)_/¯

    Sunday, July 15, 2012 9:25 PM
  • Of course in POwerSHell this takes only one little tiny line of code:

    [system.net.dns]::Resolve('technet.microsoft.com')
    HostName                                Aliases                                 AddressList
    --------                                -------                                 -----------
    technet.microsoft.akadns.net            {technet.microsoft.com}                 {157.56.12.223}


    ¯\_(ツ)_/¯

    Sunday, July 15, 2012 9:32 PM
  • [system.net.dns]::Resolve('technet.microsoft.com')
    [system.net.dns]::GetHostAddresses('technet.microsoft.com')
    [system.net.dns]::GetHostByAddress('127.0.0.1')
    [system.net.dns]::GetHostByName('www.msn.net')


    ¯\_(ツ)_/¯

    Sunday, July 15, 2012 9:41 PM
  • As there has been no activity in this thread for a few days, we assume the issue is resolved. We will mark it as "answered" to assist others in similar situations. If you disagree, please reply with further information. You can unmark the answer if you wish. If a reply helped answer your question, please mark it as the answer.


    Richard Mueller - MVP Directory Services

    Monday, July 23, 2012 3:49 PM
    Moderator