Created
January 26, 2017 15:00
-
-
Save gcch/0b5a9cf12de8f53ddc2e44ba1e50cdf0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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