最近实现的一个定时器的小程序,作为经验积累吧
简单的实现了一个定时器的小程序,类似于多线程并发操作时,超时后的程序会主动停止运行的进程,之后做了一些清理。作为积累吧,发来大家瞧瞧。#cs ____________________________________
Au3 版本: 3.3.6.1
脚本作者: wozijisun
Email: wozijisun@sina.com
QQ/TM: Test Dept.
脚本版本: v-1.0
脚本功能:
#ce _______________脚本开始_________________
#include <Timers.au3>
#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
Global $os,$config,$user,$execute_time,$mark=0,$pid="",$file,$line,$arr,$timereset
Local $time_mark = 0
Global $num,$arr_cmd,$soc_cli,$dst_cli,$is_client=0
If $CmdLine == 2 Then
$config = $CmdLine
$user = $CmdLine
Local $arr = StringSplit($config,".")
Local $brr = StringSplit($arr,"_")
_log("================================================")
_log("用户:" & $user & "执行场景:" & $brr[$brr] & @CRLF & "START->")
_log("================================================")
Else
_log("给出参数个数为:" & $CmdLine & " 出错,请检查。","error")
MsgBox(0,"INFO","执行完成!",3)
Exit
EndIf
$file = FileOpen($config, 0)
If $file = -1 Then
_log("不能打开 " & $config & " 文件,请检查。","error")
Exit
EndIf
While 1
$line = FileReadLine($file)
If @error = -1 Then ExitLoop
$arr = StringSplit($line,"=>",1)
If IsArray($arr) Then
If StringCompare($arr,"run_time") == 0 Then
$execute_time = $arr * 1000
$mark = 1
ExitLoop
EndIf
EndIf
Wend
FileClose($file)
If $mark <> 1 Then
_log("没有在 " & $config & " 文件,找到run_time配置。","error")
Exit
EndIf
;~ 设置定时器
Local $myGui = GUICreate("")
Global $over_time = 61000
Local $timeset = _Timer_SetTimer($myGui, $over_time, "_over_time")
GUISetState(@SW_HIDE)
_getcmd_process("cmd.exe")
While 1
_execute_now($config,$user)
_log("按照正常流程执行完成此次用例。" & @CRLF & "END<-")
_Timer_KillAllTimers($myGui)
;~ _Timer_KillTimer($myGui,$timereset)
GUIDelete($myGui)
MsgBox(0,"INFO","执行完成!",3)
Exit
WEnd
;~ 作者:wozijisun
;~ 创建时间:2014-10-28
;~ 功能:设置超时定时器
;~ 参数:继承参数无实际意义
;~ 返回值:无
;~ 修改人:
;~ 修改内容:
;~ 修改时间:
Func _over_time($hWnd, $Msg, $iIDTimer, $dwTime)
#forceref $hWnd, $Msg, $iIDTimer, $dwTime
Local $count=0
If $is_client == 0 Then
While 1
$count = $count + 1
Sleep(20000)
$pid = _checkcmd_process("cmd.exe")
If StringLen(StringStripWS($pid,8)) <> 0 Then
ExitLoop
Else
If $count == 3 Then
_log("一分钟内程序异常,检测不到运行迹象,请查看执行过程中的相关问题!O(∩_∩)O~)","error")
;~ _Timer_KillTimer($myGui,$timeset)
_Timer_KillAllTimers($myGui)
GUIDelete($myGui)
Exit
EndIf
ContinueLoop
EndIf
WEnd
EndIf
_Timer_KillTimer($myGui,$timeset)
$timereset = _Timer_SetTimer($myGui,$execute_time + 300000,"_exit_app") ;在原有的时间基础上延时5分钟
;~ $timereset = _Timer_SetTimer($myGui,3000,"_exit_app");测试使用
EndFunc
;~ 作者:wozijisun
;~ 创建时间:2014-10-29
;~ 功能:设置超时定时器
;~ 参数:继承参数无实际意义
;~ 返回值:无
;~ 修改人:
;~ 修改内容:
;~ 修改时间:
Func _exit_app($hWnd, $Msg, $iIDTimer, $dwTime)
#forceref $hWnd, $Msg, $iIDTimer, $dwTime
If $is_client == 0 Then
ProcessClose($pid)
EndIf
If $is_client == 1 Then
Run(@ComSpec & " /c " & $dst_cli & "cmd[""TASKKILL /F /IM meter_client.exe""]", "", Default)
Run(@ComSpec & " /c " & $dst_cli & "cmd[""rd /S /Q C:\__" & $user & "_" & @AutoItPID & "_meter_client""]", "", Default)
EndIf
If $is_client == 2 Then
Run(@ComSpec & " /c " & $dst_cli & "cmd[""kill `ps -ef | grep -v grep | grep meter_client | awk '{print $2}'`""]", "", Default)
Run(@ComSpec & " /c " & $dst_cli & "cmd[""rm -rf /home/__" & $user & "_" & @AutoItPID & "_meter_client""]", "", Default)
EndIf
If StringCompare($os,"Linux") == 0 Then
_log("执行程序超时,原因:可能meter-server主机系统的内存已被占满。","error")
Run(@ComSpec & " /c " & $soc_cli & "cmd[""kill `ps -ef | grep meter_server | grep -v grep | awk '{print $2}'`""]", "", Default)
_log("8、发包结束后,杀掉meter_server进程。")
Sleep(10000)
Run(@ComSpec & " /c " & $soc_cli & "cmd[""rm -rf /home/__" & $user & "_" & @AutoItPID & "_meter_server""]", "", Default)
_log("9、删除__" & $user & "_" & @AutoItPID & "_meter_server目录。")
EndIf
If StringCompare($os,"Windows") == 0 Then
Run(@ComSpec & " /c " & $soc_cli & "cmd[""TASKKILL /F /IM meter_server.exe""]", "", Default)
_log("7、发包结束后,杀掉meter_server进程。")
Sleep(10000)
Run(@ComSpec & " /c " & $soc_cli & "cmd[""rd /S /Q C:\__" & $user & "_" & @AutoItPID & "_meter_server""]", "", Default)
_log("8、删除__" & $user & "_" & @AutoItPID & "_meter_server目录。")
EndIf
_log("程序超时退出,请关注是不是由于meter-server端内存占用较多导致。","error")
_Timer_KillTimer($myGui,$timereset)
GUIDelete($myGui)
MsgBox(0,"INFO","执行完成!但是,超时退出",3)
Exit
EndFunc
;~ 作者:wozijisun
;~ 创建时间:2014-10-29
;~ 功能:获取当前的cmd进程id
;~ 参数:检查进程的名字
;~ 返回值:无
;~ 修改人:
;~ 修改内容:
;~ 修改时间:
Func _getcmd_process($name)
Dim $arr_process = ProcessList($name)
Local $i
For $i = 0 To $arr_process
$arr_cmd[$i] = $arr_process[$i]
$num=$num+1
Next
EndFunc
;~ 作者:wozijisun
;~ 创建时间:2014-10-29
;~ 功能:检查两次cmd进程id的结果
;~ 参数:检查进程的名字
;~ 返回值:返回pid的值
;~ 修改人:
;~ 修改内容:
;~ 修改时间:
Func _checkcmd_process($name)
Dim $arr_process = ProcessList($name)
For $i = 0 To $arr_process
Local $mark_cmd = 0
For $j = 0 To $num
If $arr_cmd[$j] == $arr_process[$i] Then
$mark = 1
ExitLoop
EndIf
Next
If $mark_cmd == 0 And StringLen(StringStripWS($arr_process[$i],8)) <> 0 Then
$pid = $arr_process[$i]
ExitLoop
EndIf
Next
Return $pid
EndFunc
;~ 作者:wozijisun
;~ 创建时间:2014-10-10
;~ 功能:立刻执行Meter程序,进行收发判断
;~ 参数:$config是给定的执行配置文件,$user是给定的执行用户名称
;~ 返回值:无
;~ 修改人:
;~ 修改内容:
;~ 修改时间:
Func _execute_now($config,$user)
Local $conf_num = 1,$c,$main_socket,$var
If FileExists($config) And StringLen(StringStripWS($user,8)) <> 0 Then
$file = FileOpen($config, 0)
; 检查打开的文件是否可读
If $file = -1 Then
_log("不能打开 " & $config & " 文件,请检查。","error")
Return
EndIf
; 每次读取一行文本,直到文件结束.
While 1
$line = FileReadLine($file)
If @error = -1 Then ExitLoop
If StringInStr($line,"",1) == 1 Then
_log("读取首行")
ContinueLoop
EndIf
If StringInStr($line,"",1) == 1 Then
;~ MsgBox(0,"xx",$conf_num)
If $conf_num == 25 Then
_log("读取最后行共" & $conf_num-1 & "行")
ExitLoop
Else
_log($config & @CRLF & "配置文件参数没有达到24个,请检查。","error")
Return
EndIf
EndIf
$arr = StringSplit($line,"=>",1)
Switch $arr
Case "meter_server"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("meter_server为空值,不能执行!")
Return
EndIf
If StringCompare(_check_file($arr),"no") == 0 Then
_log("meter_server文件不是一个正常的可执行文件!"&$arr)
Return
EndIf
$c=StringStripWS($arr,1+2)
$conf_num = $conf_num + 1
_log("meter_server=" & $arr)
Case "meter_client"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("meter_client为空值,不能执行!")
Return
EndIf
If StringCompare(_check_file($arr),"no") == 0 Then
_log("meter_client文件不是一个正常的可执行文件!"&$arr)
Return
EndIf
$c=StringStripWS($arr,1+2)
$conf_num = $conf_num + 1
_log("meter_client=" & $arr)
Case "socket_client"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("socket_client为空值,不能执行!")
Return
EndIf
If StringCompare(_check_file($arr),"no") == 0 Then
_log("socket_client文件不是一个正常的可执行文件!"&$arr)
Return
EndIf
$c=StringStripWS($arr,1+2)
$conf_num = $conf_num + 1
_log("socket_client=" & $arr)
Case "global_port"
If StringLen(StringStripWS($arr,8)) == 0 Then
$c="6677"
_log("global_port为空值,设置默认值为6677!")
ContinueLoop
EndIf
If Not StringRegExp(StringStripWS($arr,8),"^{0,}",0) Or $arr * 1 > 65535 Then
_log("global_port输入不合法的数字。"&$arr)
Return
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("global_port=" & $arr)
Case "is_os"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("is_os为空值,不能执行!")
Return
EndIf
If StringCompare(StringStripWS($arr,8),"Windows") <> 0 And StringCompare(StringStripWS($arr,8),"Linux") <> 0 Then
_log("is_os值为Windows/Linux!不为"&$arr)
Return
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("is_os=" & $arr)
Case "server_ip"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("server_ip为空值,不能执行!")
Return
EndIf
If Not StringRegExp(StringStripWS($arr,8),"^(\d{1,2}|1\d\d|2\d|25)\.(\d{1,2}|1\d\d|2\d|25)\.(\d{1,2}|1\d\d|2\d|25)\.(\d{1,2}|1\d\d|2\d|25)$",0) Then
_log("server_ip输入了非IP地址表达式。"&$arr)
Return "ng"
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("server_ip=" & $arr)
Case "listen_port"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("listen_port为空值,不能执行!")
Return
EndIf
If Not StringRegExp(StringStripWS($arr,8),"^{0,}",0) Or $arr * 1 > 65535 Then
_log("listen_port输入不合法的数字。"&$arr)
Return
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("listen_port=" & $arr)
Case "dbx_ip"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("dbx_ip为空值,不能执行!")
Return
EndIf
If Not StringRegExp(StringStripWS($arr,8),"^(\d{1,2}|1\d\d|2\d|25)\.(\d{1,2}|1\d\d|2\d|25)\.(\d{1,2}|1\d\d|2\d|25)\.(\d{1,2}|1\d\d|2\d|25)$",0) Then
_log("dbx_ip输入了非IP地址表达式。"&$arr)
Return
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("dbx_ip=" & $arr)
Case "is_agent"
If Number(StringStripWS($arr,8)) <> 0 And Number(StringStripWS($arr,8)) <> 1 Then
_log("is_agent值不在执行0(无代理) / 1(有代理)范围内!")
Return
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("is_agent=" & $arr)
Case "agent_ip"
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("agent_ip=" & $arr)
Case "agent_port"
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("agent_port=" & $arr)
Case "is_client"
If $arr * 1 <> 0 And $arr * 1 <> 1 And $arr * 1 <> 2 Then
_log("is_client值不在执行 0(无) / 1(windows) / 2(linux) 范围内!")
Return
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("is_client=" & $arr)
Case "client_ip"
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("client_ip=" & $arr)
Case "simulate_client_ip"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("simulate_client_ip为空值,不能执行!")
Return
EndIf
If Not StringRegExp(StringStripWS($arr,8),"^(\d{1,2}|1\d\d|2\d|25)\.(\d{1,2}|1\d\d|2\d|25)\.(\d{1,2}|1\d\d|2\d|25)\.(\d{1,2}|1\d\d|2\d|25)$",0) Then
_log("simulate_client_ip输入了非IP地址表达式。"&$arr)
Return
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("simulate_client_ip=" & $arr)
Case "simulate_client_port"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("simulate_client_port为空值,不能执行!")
Return
EndIf
If Not StringRegExp(StringStripWS($arr,8),"^{0,}",0) Or $arr * 1 > 65535 Then
_log("simulate_client_port输入不合法的数字。"&$arr)
Return
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("simulate_client_port=" & $arr)
Case "simulate_server_ip"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("simulate_server_ip为空值,不能执行!")
Return
EndIf
If Not StringRegExp(StringStripWS($arr,8),"^(\d{1,2}|1\d\d|2\d|25)\.(\d{1,2}|1\d\d|2\d|25)\.(\d{1,2}|1\d\d|2\d|25)\.(\d{1,2}|1\d\d|2\d|25)$",0) Then
_log("simulate_server_ip输入了非IP地址表达式。"&$arr)
Return
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("simulate_server_ip=" & $arr)
Case "simulate_server_port"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("simulate_server_port为空值,不能执行!")
Return
EndIf
If Not StringRegExp(StringStripWS($arr,8),"^{0,}",0) Or $arr * 1 > 65535 Then
_log("simulate_server_port输入不合法的数字。"&$arr)
Return
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("simulate_server_port=" & $arr)
Case "sequence"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("sequence为空值,不能执行!")
Return
EndIf
If Not StringRegExp(StringStripWS($arr,8),"{0,}",0) Then
_log("sequence输入不合法的数字。"&$arr)
Return
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("sequence=" & $arr)
Case "pcapfile"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("pcapfile为空值,不能执行!")
Return
EndIf
If StringCompare(_check_file($arr),"no") == 0 Then
_log("pcapfile不是一个正常的PCAP文件!"&$arr)
Return
EndIf
$c=StringStripWS($arr,1+2)
$conf_num = $conf_num + 1
_log("pcapfile=" & $arr)
Case "simulate_client_count"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("simulate_client_count为空值,不能执行!")
Return
EndIf
If Not StringRegExp(StringStripWS($arr,8),"^{0,}",0) Then
_log("simulate_client_count输入不合法的数字。"&$arr)
Return
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("simulate_client_count=" & $arr)
Case "connect_per_sec"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("connect_per_sec为空值,不能执行!")
Return
EndIf
If Not StringRegExp(StringStripWS($arr,8),"^{0,}",0) Then
_log("connect_per_sec输入不合法的数字。"&$arr)
Return
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("connect_per_sec=" & $arr)
Case "loop_count"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("loop_count为空值,不能执行!")
Return
EndIf
If Not StringRegExp(StringStripWS($arr,8),"^{0,}",0) Then
_log("loop_count输入不合法的数字。"&$arr)
Return
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("loop_count=" & $arr)
Case "think_time"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("think_time为空值,不能执行!")
Return
EndIf
If Not StringRegExp(StringStripWS($arr,8),"^{0,}",0) Then
_log("think_time输入不合法的数字。"&$arr)
Return
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("think_time=" & $arr)
Case "run_time"
If StringLen(StringStripWS($arr,8)) == 0 Then
_log("run_time为空值,不能执行!")
Return
EndIf
If Not StringRegExp(StringStripWS($arr,8),"^{0,}",0) Then
_log("run_time输入不合法的数字。"&$arr)
Return
EndIf
$c=StringStripWS($arr,8)
$conf_num = $conf_num + 1
_log("run_time=" & $arr)
Case Else
_log("无法识别的字符:" & $arr & "=" & $arr,"warn")
EndSwitch
Wend
FileClose($file)
;~ 判断meter-client是否需要放置在远程机器上
If $c * 1 <> 0 Then
$is_client = $c * 1
TCPStartup()
$main_socket = TCPConnect($c, $c)
If $main_socket = -1 Then
TCPCloseSocket($main_socket)
TCPShutdown()
_log("服务器端的Socket-Server服务器没有开启,请开启IP:" & $c & "<=>Port:" & $c &" 后执行。","warn")
Return
EndIf
$dst_cli = $c & " "& $c & "#" & $c & "#"
;~ windows OS
If $c * 1 == 1 Then
RunWait(@ComSpec & " /c " & $dst_cli & "cmd[""echo yes > C:\yes.log""]", "", Default)
RunWait(@ComSpec & " /c " & $dst_cli & "copyfile", "", Default)
If Not FileExists(@ScriptDir & "\yes.log") Then
_log("指定Meter客户端的操作系统可能不是Windows,请假查。")
Return
EndIf
RunWait(@ComSpec & " /c " & $dst_cli & "cmd[""del /F /Q C:\yes.log""]", "", Default)
FileDelete(@ScriptDir & "\yes.log")
;~ Linux OS
ElseIf $c * 1 == 2 Then
RunWait(@ComSpec & " /c " & $dst_cli & "cmd[""echo yes > /home/yes.log""]", "", Default)
RunWait(@ComSpec & " /c " & $dst_cli & "copyfile", "", Default)
If Not FileExists(@ScriptDir & "\yes.log") Then
_log("指定Meter客户端的操作系统可能不是Linux,请假查。")
Return
EndIf
RunWait(@ComSpec & " /c " & $dst_cli & "cmd[""rm -rf /home/yes.log""]", "", Default)
FileDelete(@ScriptDir & "\yes.log")
;~ Other OS
Else
_log("操作系统可能不是Windows / Linux,请假查。","warn")
Return
EndIf
EndIf
$soc_cli = $c & " "& $c & "#" & $c & "#"
;~ 对Server_IP进行处理,因为Server_IP是Meter-Server所在的主机,执行时需要将meter工具上传到该主机上
TCPStartup()
$main_socket = TCPConnect($c, $c)
If $main_socket = -1 Then
TCPCloseSocket($main_socket)
TCPShutdown()
_log("服务器端的Socket-Server服务器没有开启,请开启IP:" & $c & "<=>Port:" & $c &" 后执行。","warn")
Return
EndIf
;~ 对DBx_IP进行处理,因为要到DBx_IP上获取tracelog文件
TCPStartup()
$main_socket = TCPConnect($c, $c)
If $main_socket = -1 Then
TCPCloseSocket($main_socket)
TCPShutdown()
_log("服务器端的Socket-Server服务器没有开启,请开启IP:" & $c & "<=>Port:" & $c &" 后执行。","warn")
Return
EndIf
;~ 设置代理模式后,对代理进行判断,MS可以不写
;~ If $c * 1 == 1 Then
;~ TCPStartup()
;~ $main_socket = TCPConnect($c, $c)
;~ If $main_socket = -1 Then
;~ TCPCloseSocket($main_socket)
;~ TCPShutdown()
;~ _log("服务器端的Socket-Server服务器没有开启,请开启IP:" & $c & "<=>Port:" & $c &" 后执行。","warn")
;~ Return
;~ EndIf
;~ EndIf
;~ 判断meter-server所在主机的类型
If StringCompare(StringStripWS($c,8), "Windows") == 0 Then
$os = "Windows"
RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""echo yes > C:\yes.log""]", "", Default)
RunWait(@ComSpec & " /c " & $soc_cli & "copyfile", "", Default)
If Not FileExists(@ScriptDir & "\yes.log") Then
_log("服务器端的操作系统可能不是Windows,请假查。")
Return
EndIf
RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""del /F /Q C:\yes.log""]", "", Default)
FileDelete(@ScriptDir & "\yes.log")
_log("执行Windows系统,共八步。")
RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""rd /S /Q C:\__" & $user & "_" & @AutoItPID & "_meter_server""]", "", Default)
_log("1、先执行删除__meter_server目录的操作,防止影响Meter执行。")
RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""mkdir C:\__" & $user & "_" & @AutoItPID & "_meter_server""]", "", Default)
_log("2、执行创建__meter_server目录的操作。")
RunWait(@ComSpec & " /c " & $soc_cli & "sendfile["& $c &",C:\__" & $user & "_" & @AutoItPID & "_meter_server\meter_server.exe]", "", Default)
_log("3、向__meter_server目录发送meter_server程序。")
RunWait(@ComSpec & " /c " & $soc_cli & "sendfile["& $c &",C:\__" & $user & "_" & @AutoItPID & "_meter_server\meter_need.pcap]", "", Default)
_log("4、向__meter_server目录发送PCAP包。")
Run(@ComSpec & " /c " & $soc_cli & "cmd[""C:\__" & $user & "_" & @AutoItPID & "_meter_server\meter_server.exe " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & "" & " C:\__" & $user & "_" & @AutoItPID & "_meter_server\meter_need.pcap""]", "", Default)
_log("5、启动meter_server程序。")
If $c * 1 == 0 Then
RunWait(@ComSpec & " /c " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c, "", @SW_MAXIMIZE)
ElseIf $c * 1 == 1 Then
RunWait(@ComSpec & " /c " & $dst_cli & "cmd[""mkdir C:\__" & $user & "_" & @AutoItPID & "_meter_client""]", "", Default)
RunWait(@ComSpec & " /c " & $dst_cli & "sendfile["& $c &",C:\__" & $user & "_" & @AutoItPID & "_meter_client\meter_client.exe]", "", Default)
RunWait(@ComSpec & " /c " & $dst_cli & "cmd[""C:\__" & $user & "_" & @AutoItPID & "_meter_client\meter_client.exe" & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & """]", "", @SW_MAXIMIZE)
;~ RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""TASKKILL /F /IM meter_server.exe""]", "", Default)
RunWait(@ComSpec & " /c " & $dst_cli & "cmd[""rd /S /Q C:\__" & $user & "_" & @AutoItPID & "_meter_client""]", "", Default)
ElseIf $c * 1 == 2 Then
RunWait(@ComSpec & " /c " & $dst_cli & "cmd[""mkdir /home/__" & $user & "_" & @AutoItPID & "_meter_client""]", "", Default)
RunWait(@ComSpec & " /c " & $dst_cli & "sendfile["& $c &",/home/__" & $user & "_" & @AutoItPID & "_meter_client\meter_client]", "", Default)
RunWait(@ComSpec & " /c " & $dst_cli & "cmd[""/home/__" & $user & "_" & @AutoItPID & "_meter_client\meter_client" & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & """]", "", @SW_MAXIMIZE)
;~ RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""TASKKILL /F /IM meter_server.exe""]", "", Default)
RunWait(@ComSpec & " /c " & $dst_cli & "cmd[""rm -rf /home/__" & $user & "_" & @AutoItPID & "_meter_client""]", "", Default)
EndIf
_log("6、启动meter_client程序,向meter-server端发包。")
RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""TASKKILL /F /IM meter_server.exe""]", "", Default)
_log("7、发包结束后,杀掉meter_server进程。")
Sleep(10000)
RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""rd /S /Q C:\__" & $user & "_" & @AutoItPID & "_meter_server""]", "", Default)
_log("8、删除__" & $user & "_" & @AutoItPID & "_meter_server目录。")
ElseIf StringCompare(StringStripWS($c,8), "Linux") == 0 Then
$os = "Linux"
RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""echo yes > /home/yes.log""]", "", Default)
RunWait(@ComSpec & " /c " & $soc_cli & "copyfile", "", Default)
If Not FileExists(@ScriptDir & "\yes.log") Then
_log("服务器端的操作系统可能不是Linux,请假查。")
Return
EndIf
RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""rm -rf /home/yes.log""]", "", Default)
FileDelete(@ScriptDir & "\yes.log")
_log("执行Linux系统,共九步。")
RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""rm -rf /home/__" & $user & "_" & @AutoItPID & "_meter_server""]", "", Default)
_log("1、先执行删除__meter_server目录的操作,防止影响Meter执行。")
RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""mkdir /home/__" & $user & "_" & @AutoItPID & "_meter_server""]", "", Default)
_log("2、执行创建__meter_server目录的操作。")
RunWait(@ComSpec & " /c " & $soc_cli & "sendfile["& $c &",/home/__" & $user & "_" & @AutoItPID & "_meter_server/meter_server]", "", Default)
_log("3、向__meter_server目录发送meter_server程序。")
RunWait(@ComSpec & " /c " & $soc_cli & "sendfile["& $c &",/home/__" & $user & "_" & @AutoItPID & "_meter_server/meter_need.pcap]", "", Default)
_log("4、向__meter_server目录发送PCAP包。")
RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""chmod 777 /home/__" & $user & "_" & @AutoItPID & "_meter_server/*""]", "", Default)
_log("5、向__meter_server目录赋予可执行权限。")
Run(@ComSpec & " /c " & $soc_cli & "cmd[""cd /home/__" & $user & "_" & @AutoItPID & "_meter_server;./meter_server "& $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & "" & " /home/__" & $user & "_" & @AutoItPID & "_meter_server/meter_need.pcap""]", "", Default)
_log("6、启动meter_server程序。")
If $c * 1 == 0 Then
RunWait(@ComSpec & " /c " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c, "", @SW_MAXIMIZE)
ElseIf $c * 1 == 1 Then
RunWait(@ComSpec & " /c " & $dst_cli & "cmd[""mkdir C:\__" & $user & "_" & @AutoItPID & "_meter_client""]", "", Default)
RunWait(@ComSpec & " /c " & $dst_cli & "sendfile["& $c &",C:\__" & $user & "_" & @AutoItPID & "_meter_client\meter_client.exe]", "", Default)
RunWait(@ComSpec & " /c " & $dst_cli & "cmd[""C:\__" & $user & "_" & @AutoItPID & "_meter_client\meter_client.exe" & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & """]", "", @SW_MAXIMIZE)
;~ RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""TASKKILL /F /IM meter_server.exe""]", "", Default)
RunWait(@ComSpec & " /c " & $dst_cli & "cmd[""rd /S /Q C:\__" & $user & "_" & @AutoItPID & "_meter_client""]", "", Default)
ElseIf $c * 1 == 2 Then
RunWait(@ComSpec & " /c " & $dst_cli & "cmd[""mkdir /home/__" & $user & "_" & @AutoItPID & "_meter_client""]", "", Default)
RunWait(@ComSpec & " /c " & $dst_cli & "sendfile["& $c &",/home/__" & $user & "_" & @AutoItPID & "_meter_client\meter_client]", "", Default)
RunWait(@ComSpec & " /c " & $dst_cli & "cmd[""/home/__" & $user & "_" & @AutoItPID & "_meter_client\meter_client" & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & " " & $c & """]", "", @SW_MAXIMIZE)
;~ RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""TASKKILL /F /IM meter_server.exe""]", "", Default)
RunWait(@ComSpec & " /c " & $dst_cli & "cmd[""rm -rf /home/__" & $user & "_" & @AutoItPID & "_meter_client""]", "", Default)
EndIf
_log("7、启动meter_client程序,向meter-server端发包。")
RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""kill `ps -ef | grep meter_server | grep -v grep | awk '{print $2}'`""]", "", Default)
_log("8、发包结束后,杀掉meter_server进程。")
Sleep(10000)
RunWait(@ComSpec & " /c " & $soc_cli & "cmd[""rm -rf /home/__" & $user & "_" & @AutoItPID & "_meter_server""]", "", Default)
_log("9、删除__" & $user & "_" & @AutoItPID & "_meter_server目录。")
Else
_log("有病毒入侵了吗?遇到了无法解析的操作系统os=|" & $c & "|","warn")
Return
EndIf
Else
_log("当前执行的PCAP包没有传入配置文件Config或者执行者名称,程序无法正常执行。" & _
"请先配置后再执行。","warn")
Return
EndIf
EndFunc
;~ 作者:wozijisun
;~ 创建时间:2014-10-17
;~ 功能:生成Log日志
;~ 参数:message记录信息,level出错的级别(info:正常信息打印,warn:提示性错误,error:严重错误导致程序无法运行)
;~ 返回值:无
;~ 修改人:
;~ 修改内容:
;~ 修改时间:
Func _log($message,$level="info")
Local $date,$time
$date = @YEAR & "-" & @MON & "-" & @MDAY
$time = "[" & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & "-" & $level _
& "]"
If Not FileExists(@ScriptDir & "\Log\") Then
DirCreate(@ScriptDir & "\Log\")
EndIf
FileWriteLine(@ScriptDir & "\Log\" & $date & ".log",@AutoItPID & $time & $message)
EndFunc
;~ 作者:wozijisun
;~ 创建时间:2014-09-28
;~ 功能:检查文件是否存在于固定路径下
;~ 修改人:
;~ 修改内容:
;~ 修改时间:
Func _check_file($path)
Local $attr
If FileExists($path) Then
$attr = FileGetAttrib($path)
If StringInStr($attr,"N") Or StringInStr($attr,"C") Or StringInStr($attr,"O") Or StringInStr($attr,"A") Then
Return "yes"
Else
Return "no"
EndIf
Else
Return "no"
EndIf
EndFunc
;~ 作者:wozijisun
;~ 创建时间:2014-10-22
;~ 功能:检查IP地址是否为可用的IP
;~ 参数:$ip输入的IP地址
;~ 返回值:ng=Not go;ok=go
;~ 修改人:
;~ 修改内容:
;~ 修改时间:
;~ Func _check_ip($ip)
;~ Local $var
;~ If Not StringRegExp(StringStripWS($ip,8),"^(\d{1,2}|1\d\d|2\d|25)\.(\d{1,2}|1\d\d|2\d|25)\.(\d{1,2}|1\d\d|2\d|25)\.(\d{1,2}|1\d\d|2\d|25)$",0) Then
;~ _log("simulate_client_ip输入了非IP地址表达式。"&$ip)
;~ Return "ng"
;~ EndIf
;~ $var = Ping(StringStripWS($ip,8))
;~ If $var == 0 Then
;~ Switch @error
;~ Case 1
;~ _log("simulate_client_ip所在的目标主机离线。" & $ip)
;~ Return "ng"
;~ Case 2
;~ _log("simulate_client_ip所在的目标主机无法到达。" & $ip)
;~ Return "ng"
;~ Case 3
;~ _log("simulate_client_ip所在的目标主机错误。" & $ip)
;~ Return "ng"
;~ Case 4
;~ _log("simulate_client_ip所在的目标其它错误。" & $ip)
;~ Return "ng"
;~ EndSwitch
;~ Else
;~ Return "ok"
;~ EndIf
;~ EndFunc
支持一下。。
页:
[1]