没有细看代码是什么回事
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
;#NoTrayIcon
Opt("GUIOnEventMode", 1)
Opt("TrayIconDebug", 1)
Global $time = 1
If Not FileExists("srvmonitoring.ini") Then
MsgBox(0, "警告", "未发现配置文件,程序将自动退出!", 6)
Exit
EndIf
#Region ### START Koda GUI section ###
$Form1 = GUICreate("网络状态监控器 V1.0", 430, 160)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Label1 = GUICtrlCreateLabel("正在进行项目检测!", 1, 12, 430, 32, $SS_CENTER)
GUICtrlSetFont(-1, 18, 800, 0)
GUICtrlSetColor(-1, 0x0000FF)
$Edit1 = GUICtrlCreateEdit("", 0, 60, 430, 80, BitOR($WS_VSCROLL, $ES_READONLY))
GUICtrlSetBkColor(-1, 0xffffff)
Global $StatusBar1 = _GUICtrlStatusBar_Create($Form1)
Global $aParts[3] = [110, 260, -1]
_GUICtrlStatusBar_SetParts($StatusBar1, $aParts)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
AdlibEnable('SetStatusBar', 1000)
While 1
If $time = 1 Then
$time = 0
_TcpSocket()
EndIf
Sleep(1000)
WEnd
Func SetStatusBar()
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC, 2)
EndFunc
Func _TcpSocket()
Dim $a[100], $d[100], $r[100][4]
Dim $i = 1, $dz = 1, $z = 0, $x
While 1
$a[$i] = IniRead("srvmonitoring.ini", "监控", "地址" & $dz, "NoNew")
If $a[$i] = "NoNew" Then ExitLoop
$dz += 1
$i += 1
Sleep(100)
WEnd
TCPStartup()
For $i = $i - 1 To 1 Step -1
If StringRegExp(StringTrimRight($a[$i], StringLen($a[$i]) - StringInStr($a[$i], "/")), "^([1-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){2}([1-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])[:](\d{1,5})[/]$") Then
$d = StringSplit(StringReplace($a[$i], "/", ":"), ":")
For $s = 3 To 1 Step -1
$r[$i][$s] = $d[$s]
Next
$socket = TCPConnect($r[$i][1], $r[$i][2])
If $socket = -1 Then
GUICtrlSetData($Edit1, @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " " & "[" & $r[$i][3] & "]" & " 出现网络异常!" & @CRLF, "Edit")
FileWriteLine("LogTcpSocket" & @MON & @MDAY & ".txt", @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " " & "[" & $r[$i][3] & "]" & " 出现网络异常!")
$z += 1
EndIf
$x += 1
TCPCloseSocket($socket)
EndIf
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & "总项目:" & $x & "个", 0)
_GUICtrlStatusBar_SetText($StatusBar1, @TAB & "正常:" & $x - $z & "个 异常:" & $z & "个", 1)
Next
TCPShutdown()
If $z <> 0 Then
GUICtrlSetData($Label1, "警告:检测到 " & $z & " 个异常!")
GUICtrlSetColor($Label1, 0xff0000)
Else
GUICtrlSetData($Label1, "全部项目检测正常!")
GUICtrlSetColor($Label1, 0x008000)
EndIf
$time = 1
EndFunc ;==>_TcpSocket
Func Form1Close()
Exit
EndFunc ;==>Form1Close
|