如何判定现在系统是否可以上网呢?!
如题,现在有点郁闷。。。。试了好几个命令都不行 本帖最后由 afan 于 2009-9-5 02:08 编辑判断能否上Internet网直接 Ping www.google.cn有返回即可判断通,简单实用,呵呵~ ping 127.0.0.1 检查网卡
ping 网关 检查网关是否连通
ping DNS服务器 检查DNS #include<array.au3>
;;;检测本地连接是否已经连接
$_Return= DllCall("WinInet.dll","int","InternetGetConnectedState","int_ptr",0,"int",0)
;~ _ArrayDisplay($_Return)
If $_Return = 1 Then
MsgBox(0,"","本地连接已就绪!")
Else
MsgBox(0,"","本地连接错误或网络被拨出!")
EndIf
$INTERNET_CONNECTION_MODEM = 0x1
$INTERNET_CONNECTION_LAN = 0x2
$INTERNET_CONNECTION_PROXY = 0x4
$INTERNET_CONNECTION_MODEM_BUSY = 0x8
$INTERNET_RAS_INSTALLED = 0x10
$INTERNET_CONNECTION_OFFLINE = 0x20
$INTERNET_CONNECTION_CONFIGURED = 0x40
;~ http://msdn.microsoft.com/en-us/library/aa384702(VS.85).aspx
;;检查intelel是否已经连接
Local $sz_url = "http://www.google.com"
Local $u_flags = 0x00000001
Local $u_reserved = 0
Local $a_ret_val = DllCall("WinInet.dll", "int", "InternetCheckConnection", "str", $sz_url, "uint", $u_flags, "uint", $u_reserved)
ConsoleWrite($sz_url & " is connected = " & ($a_ret_val <> 0) & @CRLF)
MsgBox(0,"",$sz_url & " is connected = " & ($a_ret_val <> 0) & @CRLF)
;~ http://msdn.microsoft.com/en-us/library/aa384346(VS.85).aspx 本帖最后由 afan 于 2009-9-5 12:19 编辑
LS大虾那个判断因特网不通需要15秒左右,时间有点长~
试试我的 ping ,判断通不通仅需不到1秒,呵呵~Dim $Line, $iPid = Run("Ping www.google.cn", "", 0, 3)
AdlibRegister('test', 200) ;判断不通超时时间
While 1
$Line = StdoutRead($iPid)
If @error Then ExitLoop
If $Line <> '' Then
If StringRegExp($Line, "Pinging") Then ExitLoop (MsgBox(64, '网络状况', '广域网通畅,可以上网~! '))
EndIf
WEnd
Func test()
If $Line = '' Then Exit (MsgBox(48, '网络状况', '广域网不通,请检查 '))
EndFunc ;==>test(AdlibRegister即旧版的AdlibEnable) 呵呵,学习一下。。 我单位的网关不让ping通,而且要portal认证才能上网,这可怎么判断啊? 有时候似乎不准确,网络连接中只是特定网页打不开 网速慢时,5楼方法测试失败,4楼可行
页:
[1]