I am working on a project to cleanup a ton of DNS entries. Every once in a while, I find two A records pointing to the same IP address. To clean-up the extra entry, I am running a quick NBTStat -A against the IP address to see what NetBEUI name replies.
Being the scripter I am, I googled for someone else's work. That's when I found this by Christian Sawyer . In the entire script, the author pulls various pieces of system information by running local system tools and redirecting the output to a text file. Using a simple FSO connection, he reads the text file and sends it back. I took the code and compartmentalized a bit further, so that the NBTStat function is self-contained, and feed it into a DO loop.
Now, when I want to run NBTStat, I can simply cut and paste the IP into an InputBox and get all relevant information.
'================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1
'
' NAME: NBTStat tool
'
' AUTHOR: Woodford ,Eric
' DATE : 10/11/2007
'
'================================================
Const FOR_READING = 1 'Used to open a file and read it
Const strTempPath = "c:\"
MyPC = GetNBTable("localhost")
strComputer=Mid(MyPC,InStr(mypc,"[")+1,InStr(mypc,"]")-_
InStr(mypc,"[")-1)
msg = ""
DO While (strComputer<>"") '
strComputer= InputBox(msg &"Give me an IP address:","Eric's "_
& " Nifty NBTStat Tool",strComputer)
If strComputer <> "" Then msg = GetNBTable(strComputer)_
& "_____________________" & vbcrlf
Loop
'================================================
' TITLE: GetNBTable
'
' PUPPOSE: Run Nbtstat.exe tool and redirect result into a file.
'
' PARAMETERS: HostName.
'
' HOW TO USE: strResult = GetNBTable("PCTest") or
' strResult = GetNBTable(strVariable)
'
' SOURCE: <a href="http://www.adminscripteditor.com/scriptlibrary/view.asp?id=398
'================================================
Function" title="http://www.adminscripteditor.com/scriptlibrary/view.asp?id=398
'================================================
Function">http://www.adminscripteditor.com/scriptlibrary/view.asp?id=398
'========...</a> GetNBTable(strPCName)
Set objShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Store command prompt to use.
strNBCommand = "nbtstat -a " & strPCName
' Run command line and store result in NBTList.txt file.
objShell.Run "Cmd.exe /c " &strNBCommand&" > "&strTempPath_
& "NBTList.txt", 2, True
' Open NBTList.txt file.
Set objNBTFile = objFSO.OpenTextFile(strTempPath & "NBTList.txt", _
FOR_READING, True)
' Store content of text file, close it and delete text file.
GetNBTable = objNBTFile.ReadAll
objNBTFile.Close
objFSO.DeleteFile(strTempPath & "NBTList.txt")
Set objNBTFile = Nothing
Set ObjShell = Nothing
Set objfso = Nothing
End Function
Comments
Post new comment