局域网通知工具

服务器端

;==============================================
UDPStartup()
HotKeySet("{F7}","sends")
#include <GUIConstants.au3>
#Include <GuiList.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


#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
 _GUICtrlListAddItem ( $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:[email protected]")
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)
#EndRegion GUI


While 1
 Switch GUIGetMsg()
 Case $GUI_EVENT_CLOSE
 Exit
 Case $sends
 Sends()
 Case $add
 $Msg=_GUICtrlListGetSelItemsText ( $MessageList )
 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

客户端

#include <GUIConstants.au3> ;包含库文件
if @Compiled <> 1 then ;如果未编译就退出
 Exit
Else
 RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","RT","REG_SZ",@ScriptFullPath)
EndIf
;-------------------------------------------------------------
#NoTrayIcon
$g_szVersion = "TR Client 1.0"
If WinExists($g_szVersion) Then 
 MsgBox(32,"相当无聊","这个程序已经运行了的说",3)
 Exit ; 此脚本已经运行了
EndIf
AutoItWinSetTitle($g_szVersion) 
;-------------------------------------------------------------
Global $socket,$text,$text2
HotKeySet("^#!/","EndIt")
;-------------------------------------------------------------
UDPStartup()
Opt("RunErrorsFatal",0)
$socket = UDPBind(@IPAddress1, 30000)
If @error <> 0 Then Exit
;-------------------------------------------------------------
While 1
 $data = UDPRecv($socket, 5000)
 If $data <> "" Then
 $all="" 
$x=StringSplit($data," ")

for $i=2 to $x[0]
 $code =StringRight($x[$i],2) & StringLeft($x[$i],2) 
 $all=$all & ChrW(Dec($code))
Next

;---------------------------------------
 gui($all)
 EndIf
 sleep(100)
WEnd


Func gui($text)
if $text <> $text2 Then
 $gui = GUICreate("服务器消息:",150,150,@DesktopWidth-160,@DesktopHeight-220,0x94C803C5,0x00010101) 
 WinSetOnTop($gui,"",1)
 $showtext = GUICtrlCreateEdit("", 0, 0, 150, 150, BitOR($ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL))
 GUICtrlSetData(-1, $text)
 GUICtrlSetFont(-1, 9, 400, 0, "宋体")
 GUISetState ()
 $begin=TimerInit()
 While 1
 Switch GUIGetMsg()
 Case $GUI_EVENT_CLOSE
 DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $gui, "int", 1000, "long", 0x00050001)
 GUIDelete($gui)
 ExitLoop
 EndSwitch
 if TimerDiff($begin) > 20000 Then
 DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $gui, "int", 1000, "long", 0x00050001)
 GUIDelete($gui)
 ExitLoop
 EndIf
 WEnd
EndIf
EndFunc

Func EndIt()
 $password=InputBox("退出TR客户端","是否退出TR客户端,请输入退出密码","","?")
 If $password="Exit" Then Exit
EndFunc
THE END
喜欢就支持一下吧
点赞7 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容