Question Locked

failover script for possible ISP downtime

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

hi all,
i'm wondering if anyone can guide me to a batch script or a vps or shell (could run it on cygwin) that could help me do failover solution for possible ISP downtime (i have a windows server with two NICs) with two ISP's one of them is backup. the thing is, i'm looking for a way when a ping times out on one interface, the script immediately switches the default route to the other interface..

i'm a bit green with the whole batch/shell scripting techniques.
i've tried my luck using a shell script on cygwin but that resulted in a failure..
so any advice would be appreciated:)
thanks,
Roland

2 replies

by Member 25348569

And it also doesn't switch back! The target "test" address is, in this case, 192.168.10.1 and the "new" gateway is 192.168.0.1. The script pings the test once per minute and then resets the gateway address if the ping fails. Then it exits otherwise it just keeps running. Save it as a .vbs and put it in your Startup folder.

strAddressToPing = "192.168.10.1"
strNewGateway = "192.168.0.1"
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Do While True
Set colPings = objWMIService.ExecQuery _
("Select * from Win32_PingStatus " & "Where Address = '" & strAddressToPing & "'")
For Each objPing in colPings
If objPing.StatusCode <> 0 Then
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
arrGateways = Array(strNewGateway)
objNetCard.SetGateways(arrGateways)
Next
wscript.quit
End If
Next
wscript sleep 60000
Loop

Edited to add VERY MUCH E&OE and Caveat Cursor!

This discussion is closed to new replies.