ahi os queda el codigo del script en vb script por si le interesa a alguien
Dim DefaultGw,GwR,GwTel
GwR="169.254.0.27"
GwTel="169.254.0.200"
If RedUp Then
If Reachable("169.254.0.8") Then
'WScript.Echo "Computer is Reachable!"
Else
gw
If Reachable(DefaultGw) Then
CambiaGw
Else
If DefaultGw=GwR Then
If Reachable(GwTel) Then
CambiaGw
Else
WScript.Echo "Fallo en la red. Comprobar cable de red"
End If
ElseIf DefaultGw=GwTel Then
If Reachable(GwR) Then
CambiaGw
Else
WScript.Echo "Fallo en la red. Comprobar cable de red"
End If
End If
End If
End If
End If
'''''''''''''''''''''''''''''''''''PING''''''''''''''''''''''''''''''''''''''''''
Function Reachable(strComputer)
Set objShell = Wscript.CreateObject("Wscript.Shell")
Set objExecObject = objShell.Exec ("cmd /C ping.exe -n 4 " & strComputer )
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadLine()
If (Instr(strText, "perdidos = 0") > 0) Or (Instr(strText, "perdidos = 1") > 0) Then
Reachable=true
Exit Do
End If
Loop
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''obtener gw''''''''''''''''''''''''
sub gw ()
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set DefaultGW = objWMIService.ExecQuery _
("Select DefaultIPGateway from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each DfGw In DefaultGW
If Not IsNull(DfGw.DefaultIPGateway) Then
For i=LBound(DfGw.DefaultIPGateway) to UBound(DfGw.DefaultIPGateway)
DefaultGw=DfGw.DefaultIPGateway(i)
Next
End If
Next
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''COMPROBAR SI LA INTERFAZ ESTA UP'''''''''''''''''''''
Function RedUp()
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set DefaultGW = objWMIService.ExecQuery _
("Select DefaultIPGateway from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each DfGw In DefaultGw
If IsNull(DfGw.DefaultIPGateway) Then
WScript.Echo "Fallo en la red. Comprobar cable de red"
Else
RedUp=True
End If
Next
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''CAMBIAR GW''''''''''''''''
Function CambiaGw
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
WScript.Echo "vamos a cambiar a ..." & DefaultGw
If DefaultGw=GwR Then
arrGateways = Array(GwTel)
objNetCard.SetGateways(arrGateways)
ElseIf DefaultGw=GwTel Then
arrGateways = Array(GwR)
objNetCard.SetGateways(arrGateways)
End If
Next
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''
saludos
Dim DefaultGw,GwR,GwTel
GwR="169.254.0.27"
GwTel="169.254.0.200"
If RedUp Then
If Reachable("169.254.0.8") Then
'WScript.Echo "Computer is Reachable!"
Else
gw
If Reachable(DefaultGw) Then
CambiaGw
Else
If DefaultGw=GwR Then
If Reachable(GwTel) Then
CambiaGw
Else
WScript.Echo "Fallo en la red. Comprobar cable de red"
End If
ElseIf DefaultGw=GwTel Then
If Reachable(GwR) Then
CambiaGw
Else
WScript.Echo "Fallo en la red. Comprobar cable de red"
End If
End If
End If
End If
End If
'''''''''''''''''''''''''''''''''''PING''''''''''''''''''''''''''''''''''''''''''
Function Reachable(strComputer)
Set objShell = Wscript.CreateObject("Wscript.Shell")
Set objExecObject = objShell.Exec ("cmd /C ping.exe -n 4 " & strComputer )
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadLine()
If (Instr(strText, "perdidos = 0") > 0) Or (Instr(strText, "perdidos = 1") > 0) Then
Reachable=true
Exit Do
End If
Loop
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''obtener gw''''''''''''''''''''''''
sub gw ()
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set DefaultGW = objWMIService.ExecQuery _
("Select DefaultIPGateway from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each DfGw In DefaultGW
If Not IsNull(DfGw.DefaultIPGateway) Then
For i=LBound(DfGw.DefaultIPGateway) to UBound(DfGw.DefaultIPGateway)
DefaultGw=DfGw.DefaultIPGateway(i)
Next
End If
Next
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''COMPROBAR SI LA INTERFAZ ESTA UP'''''''''''''''''''''
Function RedUp()
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set DefaultGW = objWMIService.ExecQuery _
("Select DefaultIPGateway from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each DfGw In DefaultGw
If IsNull(DfGw.DefaultIPGateway) Then
WScript.Echo "Fallo en la red. Comprobar cable de red"
Else
RedUp=True
End If
Next
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''CAMBIAR GW''''''''''''''''
Function CambiaGw
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
WScript.Echo "vamos a cambiar a ..." & DefaultGw
If DefaultGw=GwR Then
arrGateways = Array(GwTel)
objNetCard.SetGateways(arrGateways)
ElseIf DefaultGw=GwTel Then
arrGateways = Array(GwR)
objNetCard.SetGateways(arrGateways)
End If
Next
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''
saludos