|
Each contribution is licensed to you under a License Agreement by its owner, not Microsoft. Microsoft does not guarantee the contribution or purport to grant rights to it.
|
Categories |
Verify Network Connectivity(Community)
Script Code
VBScript
' ==========================================================
'= Purpose: PING, TRACE HOSTS AND PARSE TO AID THWI=
'= ROUTING TROUBLESHOOTING =
'= CONNECTIVITY TETS=
'= Author: TOM MCGEOWN=
'= Created: 15/05/2007=
'= Modified: 21/06/2007=
' ==========================================================
'*****DECLARE CONSTANTS AND OBJECTS*****
Const FOR_APPENDING = 8
Const FOR_READING = 1
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
'*****CREATE SOME VARIABLES AND ASSIGN VALUES*****
hostlist = "server1,server2,server3,server4,server5,server6"
'CHANGE THESE VALUES TO THE HOSTS YOUI WISH TO PING AND TRACE
arrTargetHosts = Split(hostlist, ",")
'*****GET LOCAL COMPUTER NAME*****
NOTE: STRNAME WILL BE IN UPPERCASE
Set colItems = objWMIService.ExecQuery("Select * From Win32_ComputerSystem")
For Each objItem in colItems
strName = objItem.Name
Next
'*****CREATE OUTPUT FILE*****
Set objFile = objFSO.CreateTextFile(strname & "Results.txt")
'*****PING TRACE AND PARSE TRACE FOR ALL COMPUTERS IN ARRAY*****
For iCounter = Lbound (arrTargetHosts) to Ubound (arrTargetHosts)
strComputer = arrTargetHosts(iCounter)
If strName <> strComputer then
objFile.writeline strName & " to " & strComputer
PingHost
TraceRt
ParseTrace
End If
Next
'*****FUNCTIONS FOLLOW*****
Function PingHost
Set objExec = objShell.Exec("ping -n 2 -w 1000 " & strComputer)
'CALL SHELL AND PING HOST
strPingResults = LCase(objExec.StdOut.ReadAll)
'CONVERT OUTPUT TO LOWERCASE FOR EASIER PARSING AND ASSIGN TO VARIABLE
objFile.writeline(strPingResults)
'WRITE TO TEXT FILE
End Function
Function TraceRt
Set objExec = objShell.Exec("tracert " & strComputer)
'CALL SHELL AND TRACERT HOST
strTraceResults = LCase(objExec.StdOut.ReadAll)
'CONVERT OUTPUT TO LOWERCASE FOR EASIER PARSING AND ASSIGN TO VARIABLE
objFile.writeline(strTraceResults)
'WRITE TO TEXT FILE
Set objTemp = objFSO.CreateTextFile("C:\temp2.txt")
'CREATE TEMP FILE
objTemp.writeline(strTraceResults)
'WRITE TRACE TO TEMP FILE
objTemp.Close
End Function
Function ParseTrace
strToday = Date()
strTime = Time()
strStart = strName
strEnd = strComputer
strRoute = strToday & " " & strTime & "," & strStart & "," & "----->,"
Set objTemp2 = objFSO.OpenTextFile("C:\temp2.txt",FOR_READING)
'OPEN TEMP FILE
Do Until objTemp2.AtEndOfStream
'READ EACH LINE OF TEMP FILE
strText = objTemp2.ReadLine
If inStr(strText, " ms ") then 'PARSE EACH LINE OF TRACE AND APPEND TO STRROUTE
arrLine = Split(strText, " ms ")
strStep = Trim(arrLine(3))
strStep1 = Mid(strStep, 1, Len(strStep)-1)
strRoute = strRoute & strStep1 & ",----->,"
End if
Loop
objTemp2.Close
strRoute = strRoute & strEnd
Set objOut = objFSO.OpenTextFile("results.csv",FOR_APPENDING)
'OPEN CSV FILE
objOut.writeline(strRoute)
'WRITE TO CSV FILE
objOut.close
'CLOSE CSV FILE
Set objTemp = objFSO.GetFile("c:\Temp2.txt")
objTemp.delete
'DELETE TEMP FILE
End Function
Platforms
For online peer support, join
The Official Scripting Guys Forum!
To provide feedback or report bugs in sample scripts, please start a new discussion on the Discussions tab for this script.
Disclaimer
The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
Be the first to create a discussion.
|