Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I setup a VBS script to run a tracert on multiple servers ??

Status
Not open for further replies.

Pyro777

MIS
Jul 14, 2006
47
US
I need to monitor my servers in my California office and would like to setup a script to pull my servers from a text file and then display the route for each server in a text or excel format. I am very new to scripting and any help along the way would be most appreciated.

 
FSO.OpenTextFile method and ReadLine etc for reading the text file

the WshShell.Exec method on the tracert command and read stdout

if you want to display stuff in excel then i would prob go for an excel spreadsheet and write you stuff in vba to read an excel sheet with the addresses of servers and write the routes in associated cells
 
Thank you for your response on this issue. I actually found an HTA out there that uses an input box to run a tracert on whatever system you choose, I modified it to pull from a .txt file so all of my servers will be displayed in the same output box. Here it is in case you ever need it...
<html>

<head><title>Traceroute</title>

<HTA:APPLICATION ID="oHTA";

APPLICATIONNAME="Traceroute";

BORDER="thin";

BORDERSTYLE="normal";

SINGLEINSTANCE="no";

>

</head><body bgcolor="#E8E8E8" >

<font size=2 face="Century Gothic, Tahoma, Arial" color="black">

<script language="VBScript" type="text/vbscript">

InputFile = "h:\scriptlogs\smartservers.txt"

Set objShell = CreateObject("WScript.Shell")

strOut=""



Sub traceroute

Const ForReading = 1, ForWriting = 2

Dim fso, f, AllHosts, Hosts

Set fso = CreateObject("Scripting.FileSystemObject")

Set f = fso_OpenTextFile(InputFile, ForReading)

AllHosts = f.ReadAll

f.close

Set f = Nothing

Set fso = Nothing

Hosts = Split(AllHosts, vbCRLF)

For each hostname in Hosts

cmdarg="%comspec% /c tracert.exe " & hostname

Set objExCmd = objShell.Exec(cmdarg)

strOut=objExCmd.StdOut.ReadAll

Set regEx = New RegExp

regEx.Pattern = "[\f\n\r\v]+"

regEx.Global = True

regEx.Multiline = True

strOut = regEx.Replace(strOut, "<br>")

TraceOut.innerHTML= TraceOut.innerHTML & strOut & "<hr noshade>"

Next

end Sub

//-->

</script>

<p><b>Traceroute to check the Smart Server environment (Press GO) </b><hr noshade color="#000000"><br>

<p><input type="submit" name="B1" value="Go" onclick="traceroute"></p>

<div id=TraceOut></div>

<script language="JavaScript">

<!--

if (window.resizeTo) self.resizeTo(600,400);

//-->

</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top