先看VBS代码:Dim strMachines,aMachines,machine
Dim objPing,objStatus,objws
Dim connect,unconnect
Do
Machine="www.baidu.com"
Set objPing=GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" & machine & "'")
connect=0
unconnect=0
For i=1 To 10
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
unconnect=unconnect+1
Else
connect=connect+1
End If
Next
Next
If connect=10 Then
MsgBox "开网啦!"
WScript.Quit
elseif connect=0 then MsgBox "断网啦!"
WScript.Quit
End If
WScript.Sleep 3*1000
Loop
AU3代码:Dim $strMachines,$aMachines,$machine
Dim $objPing,$objStatus,$objws
Dim $connect,$unconnect
$Machine="www.baidu.com"
$objPing=objGet("winmgmts:\" & $strComputer & "\root\CIMV2")
$objPing.ExecQuery("select * from Win32_PingStatus where address = '" & $machine & "'")
$connect=0
$unconnect=0
For $i=1 To 10
For $objStatus in $objPing
If $objStatus.StatusCode="" or $objStatus.StatusCode<>0 Then
$unconnect=$unconnect+1
Else
$connect=$connect+1
EndIf
Next
MsgBox(0,"",$connect)
Next
If $connect=10 Then
_GetDHCPstatus()
GUICtrlSetColor($chk, 0xFF0000)
elseif $connect=0 then
GUICtrlSetData($chk,"没有连接到外网")
EndIf
|