[背景]本人比较懒,不想因为每次要更换网关而动这个添那个,就写了个脚本来提换网关,适合我,估计也有适合各位的,拿过去,大家可以扩展下,很方便的.....哈哈......
msgbox "用来自动切换网关的脚本"
DefaultIPGateway1=Array("192.168.x.x")
DefaultIPGateway2=Array("192.168.x.y")
DefaultIPGateway1=Array("192.168.x.x")
DefaultIPGateway2=Array("192.168.x.y")
Public Function GetIP
ComputerName="."
Dim objWMIService,colItems,objItem,objAddress
Set objWMIService = GetObject("winmgmts:\\" & ComputerName & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
For Each DefaultIPGateway in objItem.DefaultIPGateway
If DefaultIPGateway <> "" then
GetIP=DefaultIPGateway
End If
If GetIP = "192.168.x.x" then
objItem.SetGateways(DefaultIPGateway2)
Exit Function
else
objItem.SetGateways(DefaultIPGateway1)
Exit Function
End If
Next
Next
End Function
ComputerName="."
Dim objWMIService,colItems,objItem,objAddress
Set objWMIService = GetObject("winmgmts:\\" & ComputerName & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
For Each DefaultIPGateway in objItem.DefaultIPGateway
If DefaultIPGateway <> "" then
GetIP=DefaultIPGateway
End If
If GetIP = "192.168.x.x" then
objItem.SetGateways(DefaultIPGateway2)
Exit Function
else
objItem.SetGateways(DefaultIPGateway1)
Exit Function
End If
Next
Next
End Function
msgbox "被修改的网关:"+GetIP
本文转自hahazhu0634 51CTO博客,原文链接:http://blog.51cto.com/5ydycm/117577,如需转载请自行联系原作者