AU3-服务器控制客户机运行程序(UDP协议)
#include <file.au3>Dim $aRecords,$sleeptime=3000
$aRecords_ip = IniReadSection(@scrīptDir&"\filelist.ini", "客户机IP地址")
$aRecords_file = IniReadSection(@scrīptDir&"\filelist.ini", "执行文件地址")
If @error Then
MsgBox(4096, "", "发生错误,可能目标文件并非标准的INI文件.")
Exit
Endif
UDPStartup()
For $i = 1 To $aRecords_ip[0][0]
Sleep($sleeptime)
$socket = UDPOpen($aRecords_ip[$i][1], 64213)
If @error <> 0 Then Exit
For $x = 1 to $aRecords_file[0][0]
Sleep($sleeptime)
$status = UDPSend($socket,$aRecords_file[$x][1])
If $status = 0 then
MsgBox(0, "错误", "无法连接到服务器: " & @error)
Exit
Else
TrayTip("正在向 "&$aRecords_ip[$i][1]&" 发送指令:",$aRecords_file[$x][1],2)
EndIf
Next
Next
OnAutoItExit()
Func OnAutoItExit()
UDPCloseSocket($socket)
UDPShutdown()
Sleep(3000)
EndFunc
;客户端源码
#include <Array.au3>
#include <file.au3>
Opt("TrayAutoPause",0) ;0=不自动停止, 1=自动停止
Opt("TrayMenuMode",1) ;不显示系统栏菜单
Opt("RunErrorsFatal",0) ;不提示错误
TraySetIcon("explorer.exe",10) ;自定义图标
dim $socket = -1,$fileArray[1]
UDPs()
Func udps()
UDPStartup()
$ipaddress=IniRead( @scrīptDir&"\clientCfg.ini","服务器列表","服务器IP地址","192.168.0.251")
$socket = UDPBind($ipaddress, 64213)
If @error <> 0 Then Exit
While 1
$data = UDPRecv($socket, 50)
If $data <> "" Then
$data=StringSplit($data,",")
if $data[1]="quit" Then
onAutoItExit()
elseif Searchfile($fileArray,$data[1]) then
Run($data[1])
_ArrayAdd($fileArray,$data[1])
elseif $data[2]="1" Then
Run($data[1])
else
ContinueLoop
EndIf
EndIf
WEnd
EndFunc
Func OnAutoItExit()
UDPCloseSocket($socket)
UDPShutdown()
Exit
EndFunc
Func Searchfile($arrayname,$filename)
_ArraySort($arrayname)
; 搜索是否存在,存在返回 False,不存在返回 Ture
$iKeyIndex = _ArrayBinarySearch ($arrayname,$filename)
If not @error Then
Return FALSE
Else
Return True
EndIf
EndFunc
;clientCfg.ini文件内容
[服务器列表]
服务器IP地址=192.168.2.68
;filelist.ini文件内容
[客户机IP地址]
1=192.168.2.68
[执行文件地址]
命令=c:\windows\notepad.exe,0 ;0表示不强制执行多次
命令=c:\windows\regedit.exe,1 ;0表示强制执行多次
命令=quit
1111
能不能把附件传上来?页:
[1]