网关切换问题???
#include#include
#NoTrayIcon
$ip = @IPAddress1
$result = StringTrimLeft($ip,10)
For $i=1 To 40 ;IP地址为1-40的机器
If $i = $result Then
; MsgBox(0, "bbb", $result)
Dim $SetDns,$SetGateway
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
$colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
If IsObj($colItems) Then
For $objNetAdapter in $colItems
$SetGateway = "192.168.1.254"
$SetDns = "221.228.255.1"
$SetDns = "192.168.1.254"
$objNetAdapter.SetGateways($SetGateway)
$objNetAdapter.SetDNSServerSearchOrder($SetDns)
Next
EndIf
EndIf
Next
用开机通道运行后,效果如图:
客户机经常会时通时断,QQ一会上线,一会掉,感觉很不稳定,
高手帮我看看代码有没有问题!!!
多谢了! 切换完成后停用网卡在启用试试。 尝试这样。我一直这样用,没有过任何问题。
Func _SetGatway($Gateway)
Dim $SetGateway
$SetGateway = $Gateway
Local$wbemFlagReturnImmediately ,$wbemFlagForwardOnly
Local$strComputer,$objWMIService,$colItems,$objNetAdapter
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
For $objNetAdapter in $colItems
$objNetAdapter.SetGateways($SetGateway)
Next
EndFunc 还是有同样的问题存在,看来只能用其它方法试一下了 #include <GuiIPAddress.au3>
#NoTrayIcon
$ip = @IPAddress1
$result = StringTrimLeft($ip,10)
Run(@ComSpec & " /c " & " ARP -S 192.168.1.254 00-00-00-00-00-00", "", @SW_HIDE) ;绑定默认网关
For $i=1 To 15 ;IP地址为1-15的机器
Run(@ComSpec & " /c " & " ARP -S 192.168.1.254 ff-ff-ff-ff-ff-ff", "", @SW_HIDE) ;网关切换
Next
现在用一另类方法做网关切换,好像效果还不错。哈。。。。
00-00-00-00-00-00为默认网关192.168.1.254的MAC地址
ff-ff-ff-ff-ff-ff 为另一网关192.168.1.154的MAC地址,
页:
[1]