Skip to content

Instantly share code, notes, and snippets.

@gcch
Created January 26, 2017 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gcch/0b5a9cf12de8f53ddc2e44ba1e50cdf0 to your computer and use it in GitHub Desktop.
Save gcch/0b5a9cf12de8f53ddc2e44ba1e50cdf0 to your computer and use it in GitHub Desktop.
Option Explicit
' ======================================================================
'
' nslookup over VBScript
'
' Copyright (c) 2017 tag.
' <http://karat5i.blogspot.jp>
'
' ======================================================================
' Object
Dim objShell : Set objShell = WScript.CreateObject("WScript.Shell")
' Get hostname
Dim strHostname : strHostname = InputBox("Please input hostname", "nslookup")
' Execute nslookup and get result
Dim objRet : Set objRet = objShell.Exec("%comspec% /c nslookup -type=a -retry=1 -timeout=0 " & strHostname)
Dim objStdErr : Set objStdErr = objRet.StdErr
Dim flgFound : flgFound = true
Do Until objStdErr.AtEndOfStream
If Left(objStdErr.ReadLine(), 3) = "***" Then
flgFound = false
Exit Do
End If
Loop
Dim strIpAddr : strIpAddr = ""
If flgFound Then
Dim strLine
Dim objStdOut : Set objStdOut = objRet.StdOut
Do Until objStdOut.AtEndOfStream
strLine = objStdOut.ReadLine()
If Left(strLine, 7) = "Address" Then
strIpAddr = Split(strLine, " ")(2)
End If
Loop
End If
' Show result
WScript.Echo strIpAddr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment