;==============================================
UDPStartup()
HotKeySet("{F7}","sends")
#include <GUIConstants.au3>
#Include <GuiListBox.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;==============================================
#NoTrayIcon
$g_szVersion = "TR Server 1.0"
If WinExists($g_szVersion) Then Exit ; 此脚本已经运行了
AutoItWinSetTitle($g_szVersion)
;----------------------------------------------
$socket = UDPOpen(@IPAddress1, 30000)
If @error <> 0 Then Exit
Dim $Msg
#Region GUI
$MAINGUI = GUICreate("TR-NET SEND 服务器端 V1.0", 641, 481, 223, 141)
$Group1 = GUICtrlCreateGroup("输入命令:", 8, 380, 617, 89)
$sends = GUICtrlCreateButton("发送(F7)", 560, 400, 57, 57)
$commands02 = GUICtrlCreateEdit("", 16, 400, 537, 57, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("消息列表", 8, 256, 513, 113)
$MessageList = GUICtrlCreateList("", 16, 272, 497, 85,BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL,$LBS_NOTIFY))
;--------------------
$file = FileOpen("Message.txt", 0)
While 1
$line = FileReadLine($file)
If @error = -1 Then ExitLoop
_GUICtrlListBox_AddString ( $MessageList, $line )
Wend
;--------------------
GUICtrlCreateGroup("", -99, -99, 1, 1)
$add = GUICtrlCreateButton("添加",528,330,97,35)
$Group3 = GUICtrlCreateGroup("发送方式:", 528, 256, 97, 65)
$Radio1 = GUICtrlCreateRadio("NET SEND", 536, 280, 81, 17)
$Radio2 = GUICtrlCreateRadio("S/C 模式", 536, 300, 65, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("发送范围:", 8, 160, 617, 89)
$Radio3 = GUICtrlCreateRadio("单一 IP:", 24, 184, 89, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Radio4 = GUICtrlCreateRadio("消息群发:", 24, 216, 89, 17)
$Input1 = GUICtrlCreateInput(@IPAddress1, 120, 184, 105, 21)
$Input2 = GUICtrlCreateInput("", 120, 216, 105, 21)
GUICtrlSetState(-1,$GUI_DISABLE)
$Input3 = GUICtrlCreateInput("", 249, 216, 103, 21)
GUICtrlSetState(-1,$GUI_DISABLE)
;---------------------
$ip=@IPAddress1
GUICtrlSetData($Input2,StringLeft($ip,StringInStr($ip,".",0,-1)) & "1")
GUICtrlSetData($Input3,StringLeft($ip,StringInStr($ip,".",0,-1)) & "255")
;---------------------
$Label1 = GUICtrlCreateLabel("到", 232, 224, 16, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$about = GUICtrlCreateEdit("", 8, 8, 617, 145, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, "说明:" & @CRLF & "使用 NET SEND 方式发送无需客户端,只需在主机和分机上面打开Message(消息)服务.缺点是只能发送一行消息"& @CRLF & _
"客户端运行一次即可实现自启动,无需再添加注册表"& @CRLF & _
"可以定义程序目录下面的Message.txt中的内容来实现预定义文本."& @CRLF & _
"使用S/C 模式时,需要不断建立连接,理论上没有NET SEND模式快."& @CRLF & _
"使用NET SEND 模式时,需要不断调用外部程序,理论上没有S/C模式快."& @CRLF & _
"要获得最新版本,请联系thesnow:"& @CRLF & @CRLF & _
"QQ:133333542"& @CRLF & _
"MAIL:Rundll@126.com")
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)
#EndRegion GUI
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $sends
Sends()
Case $add
; _GUICtrlListBox_SetCurSel ($MessageList, 3)
$Msg = _GUICtrlListBox_GetSelItemsText ( $MessageList )
MsgBox(16, "ttt", $Msg[0])
If (Not IsArray($Msg)) Then
MsgBox(16, "我晕!~~~", "你没有选择列表项目,你还添加什么?晕!~~~~")
Else
For $i = 1 To $Msg[0]
GUICtrlSetData($commands02,$Msg[1])
Next
EndIf
EndSwitch
WEnd
Func Sends()
if BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED Then
if BitAND(GUICtrlRead($radio3), $GUI_CHECKED) = $GUI_CHECKED Then
_RunDOS("net send " & GUICtrlRead($Input1) & ' "' & GUICtrlRead($commands02) & '"')
Else
$ip=@IPAddress1
$ip=StringLeft($ip,StringInStr($ip,".",0,-1))
for $i = 1 to 255
if Ping($ip & $i,50) = 0 then
ToolTip("无法连接到:" & $ip & $i,0,0)
ContinueLoop
EndIf
_RunDOS("net send " & $ip & $i & ' "' & GUICtrlRead($commands02) & '"')
ToolTip("发送消息到:" & $ip & $i,0,0)
Next
ToolTip("")
EndIf
Else
if BitAND(GUICtrlRead($radio3), $GUI_CHECKED) = $GUI_CHECKED Then
$socket = UDPOpen(GUICtrlRead($Input1), 30000)
If @error <> 0 Then Exit
$myMsg=UnicodeHex(@HOUR & ":" & @MIN & ":" & @SEC & ":" & @CRLF & GUICtrlRead($commands02))
$status = UDPSend($socket, $myMsg)
GUICtrlSetData($commands02, "")
If $status = 0 then
MsgBox(32, "错误", "发送消息错误.错误代号为: " & @error)
EndIf
UDPCloseSocket($socket)
Else
$ip=@IPAddress1
$ip=StringLeft($ip,StringInStr($ip,".",0,-1))
for $i = 1 to 255
if Ping($ip & $i,50) = 0 then
ToolTip("无法连接到:" & $ip & $i,0,0)
ContinueLoop
EndIf
$socket = UDPOpen($ip & $i, 30000)
If @error <> 0 Then Exit
$myMsg=UnicodeHex(@HOUR & ":" & @MIN & ":" & @SEC & ":" & @CRLF & GUICtrlRead($commands02))
$status = UDPSend($socket, $myMsg)
GUICtrlSetData($commands02, "")
If $status = 0 then
MsgBox(32, "错误", "发送消息错误.错误代号为: " & @error)
EndIf
UDPCloseSocket($socket)
ToolTip("发送消息到:" & $ip & $i,0,0)
Next
ToolTip("")
EndIf
EndIf
EndFunc
Func OnAutoItExit()
UDPCloseSocket($socket)
UDPShutdown()
EndFunc
Func UnicodeHex($string)
Local $char
Local $code
Local $all=""
For $i = 1 to StringLen($string)
$char = StringMid($string, $i, 1)
$code = Hex(Ascw($char),4)
$code =StringRight($code,2) & StringLeft($code,2)
$all=$all & " " & $code
Next
Return $all
EndFunc
Func _RunDOS($sCommand)
Return RunWait(@ComSpec & " /C " & $sCommand, "", @SW_HIDE)
EndFunc ;==>_RunDOS
用MsgBox(16, "ttt", $Msg[0]) 读取到的数据永远是0,但用_GUICtrlListBox_SetCurSel ($MessageList, 3)设置选择项目又很正常的,不知是什么原因,请高手指教了!!! |