How can I traceroute host and only get error text if error occurs?

Is it possible to traceroute a host, but only get error text if tracing fails?

Q: tracert.exe command always returns a bunch of text. How can I ignore it if trace finished successfully?

A: The trick is to store entire traceroute (tracert.exe) output, parse it and only return text if typical errors indicators (words) have been detected.

Please download archive from our scripts library.

Inside, you will find file traceroute-host.txt and “readme” file with installation instructions. At the moment, we assume you have created folder C:\scripts and unpacked the mentioned file there.

After you unpack it, rename traceroute-host.txt to traceroute-host.vbs.

Now open IPHost GUI client and create Script or Program monitor. At stage 3 of monitor creation wizard, enter script location and specify command-line arguments:

Script or Program monitor creation, step 3

Note that this script takes single argument: host name to trace. is chosen for the sake of example.

Switch to State conditions tab, and create Down state condition: it only should return zero in case of success; any other value means error (Down state):

Create Script or Program monitor - specify acceptable return value for tracert

Click on “Finish” to conclude and start the monitor. In the example above, is periodically traced. Note: change hops number (in the script: parameter “-h” passed to tracert.exe, on line 11), if tracing takes more than 5 hops. Note that every hop means up to 2 additional seconds of waiting (parameter “-w” passed to tracert.exe), thus too many hops cap can cause the entire script to time out.

Note: if you wish to modify the script, use cscript utility to debug it. Open cmd.exe, and issue commands:

cd C:\scripts
cscript //nologo traceroute-host.vbs

to imitate the script behavior as in the example above. Note: use actual folder name you keep the script in.