|
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_Outfile=D:\Users\grubb\Desktop\监控\PING2.exe
#PRE_UseX64=n
#PRE_Res_requestedExecutionLevel=None
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <TabConstants.au3>
Opt("TrayMenuMode", 1)
$g_szVersion = "网络检测"
If WinExists($g_szVersion) Then Exit ; 此脚本已经运行了
AutoItWinSetTitle($g_szVersion)
$Form1 = GUICreate("网络检测", 320, 380, -1, -1)
$Button1 = GUICtrlCreateButton("开始检测", 80, 330, 73, 25)
$Button2 = GUICtrlCreateButton("停止检测", 184, 330, 73, 25)
$Input1 = GUICtrlCreatelabel("本地网关", 26, 34, 105, 21,BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_READONLY,$WS_BORDER))
GUICtrlSetBkColor($Input1,0x6CA6CD)
GUICtrlSetFont($Input1, 11, 800, 0, "微软雅黑")
$Input2 = GUICtrlCreatelabel("ERP地址", 26, 64, 105, 21, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_READONLY, $WS_BORDER))
GUICtrlSetBkColor($Input2,0x6CA6CD)
GUICtrlSetFont($Input2, 11, 800, 0, "微软雅黑")
$Input3 = GUICtrlCreatelabel("内网DNS", 26, 94, 105, 21, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_READONLY, $WS_BORDER))
GUICtrlSetBkColor($Input3,0x6CA6CD)
GUICtrlSetFont($Input3, 11, 800, 0, "微软雅黑")
$Input4 = GUICtrlCreatelabel("京东主页", 26, 124, 105, 21, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_READONLY, $WS_BORDER))
GUICtrlSetBkColor($Input4,0x6CA6CD)
GUICtrlSetFont($Input4 ,11, 800, 0, "微软雅黑")
$Input5 = GUICtrlCreatelabel("CRM地址", 26, 154, 105, 21, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_READONLY, $WS_BORDER))
GUICtrlSetBkColor($Input5,0x6CA6CD)
GUICtrlSetFont($Input5, 11, 800, 0, "微软雅黑")
$Input5 = GUICtrlCreateInput("本机网关地址:", 66, 280, 180, 21, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_READONLY, $WS_BORDER))
$Input9 = GUICtrlCreateInput("", 151, 34, 41, 21, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_READONLY, $WS_BORDER))
$Input10 = GUICtrlCreateInput("", 151, 64, 41, 21, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_READONLY, $WS_BORDER))
$Input11 = GUICtrlCreateInput("", 151, 94, 41, 21, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_READONLY, $WS_BORDER))
$Input12 = GUICtrlCreateInput("", 151, 124, 41, 21, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_READONLY, $WS_BORDER))
$Input13 = GUICtrlCreateInput("", 151, 154, 41, 21, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_READONLY, $WS_BORDER))
$Input17 = GUICtrlCreateInput('延迟:', 210, 34, 80, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY, $WS_BORDER))
$Input18 = GUICtrlCreateInput("延迟:", 210, 64, 80, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY, $WS_BORDER))
$Input19 = GUICtrlCreateInput("延迟:", 210, 94, 80, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY, $WS_BORDER))
$Input20 = GUICtrlCreateInput("延迟:", 210, 124, 80, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY, $WS_BORDER))
$Input21 = GUICtrlCreateInput("延迟:", 210, 154, 80, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY, $WS_BORDER))
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
$ip_gateway = _Gateway()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
GUICtrlSetData($Input5, "本机网关地址:")
;Call(stop)
Call(_Gateway)
If $ip_gateway = 0 Then
$msg = MsgBox(0, "ERROR", "无法获取本地网关,请检查网线是否连接且已通过认证")
GUICtrlSetData($Input5, "未获取到网络地址")
Else
GUICtrlSetData($Input5, "本机网关地址:" & $ip_gateway)
Call(ping1)
EndIf
Case $Button2 ;停止PING
Call(stop)
;AdlibUnRegister(ping1)
;GUICtrlSetData($Input17, "延迟:")
;GUICtrlSetData($Input9, "")
;GUICtrlSetData($Input18, "延迟:")
;GUICtrlSetData($Input10, "")
;GUICtrlSetData($Input19, "延迟:")
;GUICtrlSetData($Input11, "")
;GUICtrlSetData($Input20, "延迟:")
;GUICtrlSetData($Input12, "")
;GUICtrlSetData($Input21, "延迟:")
;GUICtrlSetData($Input13, "")
;GUICtrlSetData($Input5, "本机网关地址:")
EndSwitch
WEnd
$ip_gateway = _Gateway()
Dim $IPGateway
Dim $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
Dim $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", 0x10 + 0x20)
Func _Gateway()
Dim $IPGateway
Dim $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
Dim $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", 0x10 + 0x20)
For $objItem In $colItems
$IPGateway = $objItem.DefaultIPGateway(0)
If StringInStr($IPGateway, ".") > 0 Then ExitLoop
Next
If StringRegExpReplace($IPGateway, '(\d+\.){12}', '') = "" Then
MsgBox(0, "ERROR", "无法获取本地网关,请检查网线是否连接且已通过认证")
Else
Return StringRegExpReplace($IPGateway, '(\d+\.){12}', '')
EndIf
EndFunc ;==>_Gateway
Func stop()
AdlibUnRegister(ping1)
GUICtrlSetData($Input17, "延迟:")
GUICtrlSetData($Input9, "")
GUICtrlSetData($Input18, "延迟:")
GUICtrlSetData($Input10, "")
GUICtrlSetData($Input19, "延迟:")
GUICtrlSetData($Input11, "")
GUICtrlSetData($Input20, "延迟:")
GUICtrlSetData($Input12, "")
GUICtrlSetData($Input21, "延迟:")
GUICtrlSetData($Input13, "")
GUICtrlSetData($Input5, "本机网关地址:")
EndFunc
Func Ping1()
$p1 = Ping($ip_gateway, 4000)
If $p1 > 0 And $p1 < 30 Then
GUICtrlSetData($Input17, "延迟:" & $p1 & " MS")
GUICtrlSetData($Input9, "良好")
GUICtrlSetColor($Input9, 0x32CD32)
ElseIf $p1 >= 30 And $p1 < 60 Then
GUICtrlSetData($Input17, "延迟:" & $p1 & " MS")
GUICtrlSetData($Input9, "正常")
GUICtrlSetColor($Input9, 0x436EEE)
ElseIf $p1 >= 60 And $p1 < 120 Then
GUICtrlSetData($Input17, "延迟:" & $p1 & " MS")
GUICtrlSetData($Input9, "较差")
GUICtrlSetColor($Input9, 0xEEB422)
ElseIf $p1 >= 120 Then
GUICtrlSetData($Input17, "延迟:" & $p1 & " MS")
GUICtrlSetData($Input9, "异常")
GUICtrlSetColor($Input9, 0xEE0000)
ElseIf $p1 = 0 Then
GUICtrlSetData($Input17, "延迟:超时")
GUICtrlSetData($Input9, "异常")
GUICtrlSetColor($Input9, 0xEE0000)
EndIf
$p2 = Ping("erp.jd.com", 4000)
If $p2 > 0 And $p2 < 30 Then
GUICtrlSetData($Input18, "延迟:" & $p2 & " MS")
GUICtrlSetData($Input10, "良好")
GUICtrlSetColor($Input10, 0x32CD32)
ElseIf $p2 >= 30 And $p2 < 60 Then
GUICtrlSetData($Input18, "延迟:" & $p2 & " MS")
GUICtrlSetData($Input10, "正常")
GUICtrlSetColor($Input10, 0x436EEE)
ElseIf $p2 >= 60 And $p2 < 120 Then
GUICtrlSetData($Input18, "延迟:" & $p2 & " MS")
GUICtrlSetData($Input10, "较差")
GUICtrlSetColor($Input10, 0xEEB422)
ElseIf $p2 >= 120 Then
GUICtrlSetData($Input18, "延迟:" & $p2 & " MS")
GUICtrlSetData($Input10, "异常")
GUICtrlSetColor($Input10, 0xEE0000)
ElseIf $p2 = 0 Then
GUICtrlSetData($Input18, "延迟:超时")
GUICtrlSetData($Input10, "异常")
GUICtrlSetColor($Input10, 0xEE0000)
EndIf
$p3 = Ping("172.17.23.148", 4000)
If $p3 > 0 And $p3 < 30 Then
GUICtrlSetData($Input19, "延迟:" & $p3 & " MS")
GUICtrlSetData($Input11, "良好")
GUICtrlSetColor($Input11, 0x32CD32)
ElseIf $p3 >= 30 And $p3 < 60 Then
GUICtrlSetData($Input19, "延迟:" & $p3 & " MS")
GUICtrlSetData($Input11, "正常")
GUICtrlSetColor($Input11, 0x436EEE)
ElseIf $p3 >= 60 And $p3 < 120 Then
GUICtrlSetData($Input19, "延迟:" & $p3 & " MS")
GUICtrlSetData($Input11, "较差")
GUICtrlSetColor($Input11, 0xEEB422)
ElseIf $p3 >= 120 Then
GUICtrlSetData($Input19, "延迟:" & $p3 & " MS")
GUICtrlSetData($Input11, "异常")
GUICtrlSetColor($Input11, 0xEE0000)
ElseIf $p3 = 0 Then
GUICtrlSetData($Input19, "延迟:超时")
GUICtrlSetData($Input11, "异常")
GUICtrlSetColor($Input11, 0xEE0000)
EndIf
$p4 = Ping("www.jd.com", 4000)
If $p4 > 0 And $p4 < 30 Then
GUICtrlSetData($Input20, "延迟:" & $p4 & " MS")
GUICtrlSetData($Input12, "良好")
GUICtrlSetColor($Input12, 0x32CD32)
ElseIf $p4 >= 30 And $p4 < 60 Then
GUICtrlSetData($Input20, "延迟:" & $p4 & " MS")
GUICtrlSetData($Input12, "正常")
GUICtrlSetColor($Input12, 0x436EEE)
ElseIf $p4 >= 60 And $p4 < 120 Then
GUICtrlSetData($Input20, "延迟:" & $p4 & " MS")
GUICtrlSetData($Input12, "较差")
GUICtrlSetColor($Input12, 0xEEB422)
ElseIf $p4 >= 120 Then
GUICtrlSetData($Input20, "延迟:" & $p4 & " MS")
GUICtrlSetData($Input12, "异常")
GUICtrlSetColor($Input12, 0xEE0000)
ElseIf $p4 = 0 Then
GUICtrlSetData($Input20, "延迟:超时")
GUICtrlSetData($Input12, "异常")
GUICtrlSetColor($Input12, 0xEE0000)
EndIf
$p5 = Ping("crm.jd.com", 4000)
If $p5 > 0 And $p5 < 30 Then
GUICtrlSetData($Input21, "延迟:" & $p5 & " MS")
GUICtrlSetData($Input13, "良好")
GUICtrlSetColor($Input13, 0x32CD32)
ElseIf $p5 >= 30 And $p5 < 60 Then
GUICtrlSetData($Input21, "延迟:" & $p5 & " MS")
GUICtrlSetData($Input13, "正常")
GUICtrlSetColor($Input13, 0x436EEE)
ElseIf $p5 >= 60 And $p5 < 120 Then
GUICtrlSetData($Input21, "延迟:" & $p5 & " MS")
GUICtrlSetData($Input13, "较差")
GUICtrlSetColor($Input13, 0xEEB422)
ElseIf $p5 >= 120 Then
GUICtrlSetData($Input21, "延迟:" & $p5 & " MS")
GUICtrlSetData($Input13, "异常")
GUICtrlSetColor($Input13, 0xEE0000)
ElseIf $p5 = 0 Then
GUICtrlSetData($Input21, "延迟:超时")
GUICtrlSetData($Input13, "异常")
GUICtrlSetColor($Input13, 0xEE0000)
EndIf
EndFunc ;==>Ping1
代码如下,问题1:WIN10环境下,只是断开网络连接,程序崩溃。
问题2:断开网络连接,按我的思路,执行65 66 67行,但是实际情况只执行了66行,且跳到了69行去执行了,请问问题出在哪。感谢 |
|