troubleshooting Question

Script to read and ping default gateway needs an enhancement

Avatar of masterbaker
masterbakerFlag for United States of America asked on
Visual Basic.NET
8 Comments1 Solution3156 ViewsLast Modified:
Hi all,

I have taken a script I found out on the Internet somewhere and hacked it up to do what I needed for part of an overall "network health check".  What this script should do is grab my default gateway, try to ping it, and let me know the results.  The script is posted below.  

My problem is that when the network connection is disconnected, the script fails on this line:

Set objExec = objShell.Exec("ping " & strTarget(1))

How can I enhance this script to do one of these two things (#1 being the preferred):

#1: Report a third message that the media is disconnected

#2: Report the same "Default Gateway is DOWN" message



Dim oShell
Dim oShellExec, oStdOutputText,sText, strTarget, sCMD
sCMD = "%comspec% /c route print"
Set oShell = CreateObject("Wscript.Shell")
Set oShellExec = oShell.Exec(sCMD)
set oStdOutputText = oShellExec.StdOut
Do While Not oStdOutputText.AtEndOfStream
sText = oStdOutputText.ReadLine
If InStr(sText, "Default Gateway") <> 0 Then
strTarget = split(sText,":")
exit do
End If

Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec("ping " & strTarget(1))
strPingResults = LCase(objExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
  WScript.Echo "Local router is UP"
  WScript.Echo "******** Local router is DOWN ********"
End If
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros