Taipen
Taipen

Reputation: 13

Simple vbscript script that checks internet link's healthiness and switches to backup connection if main dropped

I need to come up with simple solution for an internet gw in SOHO environment. It has 2 internet connections - main via adsl link and backup via USB 3G modem. Both connections export standard PPP interface, so them can easily be switched on/off via command line or scripts. Script has to be able:

  1. check if main internet connection still available, say, every 30 seconds.
  2. if it haven't been available for, say, 10 times in a row (that means, for ~300 seconds), it have to disconnect main connection (if its still connected), and try to reconnect it
  3. if (2) didn't solve the problem, it have to disconnect main connection (again, if its connected at all) and proceed to turning on the backup conn-n.
  4. if (3) was carried on successfully, it have to on regular basis (like, say, every hour) try to switch back to main conn-n, to be sure it still isn't available, and if it isn't, then fallback to backup again. If it IS, then stay at main one.
  5. be able to mirror all above transitions in simple text log file.

Any suggestions and useful code snippets/fragments I can borrow, to make these task easier?

Upvotes: 1

Views: 2542

Answers (1)

peter
peter

Reputation: 42192

With the following script you can check is a connection is up, add a few sleeps and loops and you are good.

Function ExecPing(strTarget)
  Set objShell = CreateObject("WScript.Shell")
  Set objExec = objShell.Exec("ping -n 2 -w 1000 " & strTarget)
  strPingResults = LCase(objExec.StdOut.ReadAll)
  If InStr(strPingResults, "reply from") Then 
    WScript.Echo VbCrLf & strTarget & " responded to ping."
    ExecPing = True
  Else
    WScript.Echo VbCrLf & strTarget & " did not respond to ping."
    ExecPing = False
  End If
End Function

ExecPing inputbox( "Give the ip/unc/url to ping:")

Upvotes: 2

Related Questions