本帖最后由 wllx 于 2023-10-5 17:11 编辑
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- _winapi_wow64enablewow64fsredirection(false)
- local $cofing = @scriptdir & "\wim\jydn\lan.ini", $fonts = "微软雅黑"
- _skins3()
- local $tcpport = 8411, $tcpip = @ipaddress1
- local $_tcp_hsockets[1][10], $recvone = 0, $delsocket = -1, $connectedsocket, $recvtcp = 0
- local $tcprecvmode, $postsk, $mainstr = "####", $recvbtos, $recvold, $error
- local $mainsocket = tcplisten($tcpip, $tcpport)
- local $mht = guicreate("远程控制", 326, 500)
- local $listview3 = guictrlcreatelistview("", 10, 10, 306, 480)
- _guictrllistview_settextbkcolor($listview3, 6027594)
- _guictrllistview_addcolumn($listview3, "", 0)
- _guictrllistview_addcolumn($listview3, "socket", 0)
- _guictrllistview_addcolumn($listview3, "客户端名称", 145, 2)
- _guictrllistview_addcolumn($listview3, "客户端ip地址", 145, 2)
- $listmenu = guictrlcreatecontextmenu($listview3)
- $reboot= guictrlcreatemenuitem("重启客户端", $listmenu)
- guictrlsetfont(-1, 9, 400, 1, $fonts)
- $boot = guictrlcreatemenuitem("关闭客户端", $listmenu)
- guictrlsetfont(-1, 9, 400, 1, $fonts)
- $tightvnc= guictrlcreatemenuitem("连接客户端", $listmenu)
- guictrlsetfont(-1, 9, 400, 1, $fonts)
- guisetstate()
- tcpstartup()
- local $mainsocket = tcplisten(iniread($cofing, "lan", "tcpip ", ""), $tcpport)
- guiregistermsg($wm_command, "wm_notify")
- mytcp_server($tcpip, $tcpport)
- while 1
- _tcprecv()
- _while()
- wend
- func _while()
- $nmsg = guigetmsg()
- switch $nmsg
- case $gui_event_close, $idclose
- exit
- endswitch
- endfunc ;==>_while
- func quit()
- tcpshutdown()
- exit
- endfunc ;==>quit
- func wm_notify($hwnd, $imsg, $iwparam, $ilparam)
- local $hwndfrom
- $hwndfrom = $ilparam
- switch $iwparam
- case $tightvnc
- $index = controllistview($mht, "", "[class:syslistview32; instance:1]", "getselected", 3)
- if $index <> "" then
- $ip = controllistview($mht, "", "[class:syslistview32; instance:1]", "gettext", $index, 3)
- traytip("通知", " " &"正在连接" &"☛"& $ip , 1, 1)
- run(@comspec & " /c " & @scriptdir & "\dysoft\tvnviewer.exe" & " " & $ip, @scriptdir, @sw_hide)
- endif
- return true
- case $reboot
- $index = controllistview($mht, "", "[class:syslistview32; instance:1]", "getselected", 3)
- if $index <> "" then
- $ip = controllistview($mht, "", "[class:syslistview32; instance:1]", "gettext", $index, 3)
- traytip("通知", " " &"正在重启" &"☛"& $ip , 1, 1)
- run(@comspec & ' /c ' & 'shutdown -m \\' & $ip & ' -r -f -t 0', '@scriptdi', @sw_hide)
- endif
- return true
- case $boot
- $index = controllistview($mht, "", "[class:syslistview32; instance:1]", "getselected", 3)
- if $index <> "" then
- $ip = controllistview($mht, "", "[class:syslistview32; instance:1]", "gettext", $index, 3)
- traytip("通知", " " &"正在关机" &"☛"& $ip , 1, 1)
- run(@comspec & ' /c ' & 'shutdown -m \\' & $ip & ' -s -f -t 0', '@scriptdi', @sw_hide)
- endif
- return true
- endswitch
- endfunc ;==>wm_notify
- func mytcp_server($tcpip, $tcpport)
- local $ilistensocket = tcplisten($tcpip, $tcpport , 250)
- local $ierror = 0
- if @error then
- $ierror = @error
- return false
- endif
- local $isocket = 0
- do
- $isocket = tcpaccept($ilistensocket)
- if @error then
- $ierror = @error
- return false
- endif
- if guigetmsg() = $gui_event_close then return false
- until $isocket <> -1
- tcpclosesocket($ilistensocket)
- local $sreceived = tcprecv($isocket, 4)
- tcpclosesocket($isocket)
- endfunc ;==>mytcp_server
- func _tcprecv()
- local $regsocket = -1, $regip, $rdays
- dim $regsocket = tcpaccept($mainsocket)
- if $regsocket <> -1 then
- dim $recv_1 = tcprecv($regsocket, 1024 * 1024, 1)
- if @error then
- $error = int(@error)
- endif
- if $recv_1 <> "" then
- $checkdata = stringleft($recv_1, 12)
- if $checkdata = "0x232323232b" then
- $regip = sockettoip($regsocket)
- $recvbtos = binarytostring($recv_1, 4)
- $rdays = stringsplit($recvbtos, " ", 1)
- if isarray($rdays) then
- if ubound($rdays) > 3 then
- if stringupper($rdays[4]) = stringupper("sendname") then
- _socketact($regsocket, $regip, $rdays[5], "sendname")
- dim $onlinepclist = ""
- for $i = 1 to ubound($_tcp_hsockets) - 1
- $onlinepclist = $onlinepclist & $_tcp_hsockets[$i][0] & "|" & $_tcp_hsockets[$i][2] & ","
- next
- endif
- endif
- endif
- endif
- endif
- else
- if (ubound($_tcp_hsockets)) > 1 then
- for $i = 1 to ubound($_tcp_hsockets) - 1
- dim $recv_1 = tcprecv($_tcp_hsockets[$i][0], 1024 * 1024, 1)
- if @error then
- $error = int(@error)
- if $error = 10054 then
- if $_tcp_hsockets[$i][0] <> -1 then
- $delsocket = $_tcp_hsockets[$i][0]
- tcpclosesocket($_tcp_hsockets[$i][0])
- endif
- endif
- endif
- if $recv_1 <> "" then
- $postsk = $_tcp_hsockets[$i][0]
- endif
- next
- if $delsocket <> -1 then
- _tcp_server_broadcast($delsocket, "offline")
- endif
- endif
- endif
- endfunc ;==>_tcprecv
- func _socketact($socketid = -1, $socketip = "", $socketname = "", $mode = "add")
- if $socketid <> -1 and $socketip <> "" and $socketname <> "" then
- dim $name_and_ip = $socketname & "|" & $socketip
- dim $so_name_and_ip = _arrayfindall($_tcp_hsockets, $socketid, 0, 0, 0, 0, 0)
- if isarray($so_name_and_ip) then
- tcpclosesocket($_tcp_hsockets[$so_name_and_ip[0]][0])
- $_tcp_hsockets[$so_name_and_ip[0]][0] = $socketid
- $_tcp_hsockets[$so_name_and_ip[0]][3] = 1
- assign("gsocket" & $socketid, $so_name_and_ip[0], 2)
- _tcp_server_broadcast($socketid, "online")
- else
- dim $recvubound = ubound($_tcp_hsockets)
- redim $_tcp_hsockets[$recvubound 1][10]
- $_tcp_hsockets[$recvubound][0] = $socketid
- $_tcp_hsockets[$recvubound][1] = $socketip
- $_tcp_hsockets[$recvubound][2] = $name_and_ip
- $_tcp_hsockets[$recvubound][3] = 1
- assign("gsocket" & $socketid, $recvubound, 2)
- _tcp_server_broadcast($socketid, "online")
- endif
- endif
- endfunc ;==>_socketact
- func _tcp_server_broadcast($stext = "", $sendtype = "msg")
- if stringupper($sendtype) = stringupper("online") or stringupper($sendtype) = stringupper("offline") then
- dim $stexta = $_tcp_hsockets[eval("gsocket" & $stext)][0] & "|" & $_tcp_hsockets[eval("gsocket" & $stext)][2]
- _clientline($stexta, $sendtype)
- else
- dim $stexta = $stext
- endif
- if (ubound($_tcp_hsockets)) > 1 then
- dim $sendmsg = stringtobinary($mainstr & " 0 " & $sendtype & " " & $stexta & ", ", 4)
- for $i = 1 to ubound($_tcp_hsockets) - 1
- if stringupper($sendtype) = stringupper("online") or stringupper($sendtype) = stringupper("offline") then
- if ubound($_tcp_hsockets) > $i then
- if $_tcp_hsockets[$i][0] and $_tcp_hsockets[$i][0] <> $stext then
- tcpsend($_tcp_hsockets[$i][0], $sendmsg)
- if @error then
- $error = int(@error)
- if $_tcp_hsockets[$i][0] <> -1 then
- $delsocket = $_tcp_hsockets[$i][0]
- tcpclosesocket($_tcp_hsockets[$i][0])
- endif
- if $delsocket <> -1 then
- _tcp_server_broadcast($delsocket, "offline")
- endif
- endif
- endif
- endif
- else
- if $_tcp_hsockets[$i][0] then
- tcpsend($_tcp_hsockets[$i][0], $sendmsg)
- if @error then
- $error = int(@error)
- if $_tcp_hsockets[$i][0] <> -1 then
- $delsocket = $_tcp_hsockets[$i][0]
- tcpclosesocket($_tcp_hsockets[$i][0])
- if $delsocket <> -1 then
- _tcp_server_broadcast($delsocket, "offline")
- endif
- endif
- endif
- endif
- endif
- next
- if $delsocket <> -1 then
- _arraydelete($_tcp_hsockets, eval("gsocket" & $delsocket))
- assign("gsocket" & $delsocket, -1, 2)
- $delsocket = -1
- endif
- endif
- endfunc ;==>_tcp_server_broadcast
- func _clientline($sonlineipstr = "", $sonlinemode = "")
- if $sonlineipstr <> "" then
- dim $sonlinesp = stringsplit($sonlineipstr, "|", 1)
- if isarray($sonlinesp) then
- if ubound($sonlinesp) > 3 then
- dim $sonlinesocket = $sonlinesp[1]
- dim $sonlinename = $sonlinesp[2]
- dim $sonlineip = $sonlinesp[3]
- dim $getitemcount = _guictrllistview_getitemcount($listview3)
- dim $sonline_id = _guictrllistview_findintext($listview3, $sonlinename & "|" & $sonlineip)
- if $sonline_id <> -1 then
- if stringupper($sonlinemode) = stringupper("offline") then
- traytip("通知", " " & $sonlineipstr & "已断开", 1, 1)
- _guictrllistview_deleteitem(guictrlgethandle($listview3), $sonline_id)
- else
- traytip("通知", " " & $sonlinename & "已连接.", 1, 1)
- _guictrllistview_setitem($listview3, $sonlinesocket, $sonline_id, 1)
- endif
- else
- if stringupper($sonlinemode) = stringupper("online") then
- traytip("通知", " " & $sonlinename & "已连接.", 1, 1)
- _guictrllistview_additem($listview3, $sonlinename & "|" & $sonlineip, $getitemcount)
- _guictrllistview_addsubitem($listview3, $getitemcount, $sonlinesocket, 1, 1)
- _guictrllistview_addsubitem($listview3, $getitemcount, $sonlinename, 2, 1)
- _guictrllistview_addsubitem($listview3, $getitemcount, $sonlineip, 3, 1)
- endif
- endif
- endif
- endif
- endif
- endfunc ;==>_clientline
- func sockettoip($shocket)
- local $sockaddr, $aret
- $sockaddr = dllstructcreate("short;ushort;uint;char[8]")
- $aret = dllcall("ws2_32.dll", "int", "getpeername", "int", $shocket, "ptr", dllstructgetptr($sockaddr), "int*", dllstructgetsize($sockaddr))
- if not @error and $aret[0] = 0 then
- $aret = dllcall("ws2_32.dll", "str", "inet_ntoa", "int", dllstructgetdata($sockaddr, 3))
- if not @error then $aret = $aret[0]
- else
- $aret = 0
- endif
- $sockaddr = 0
- return $aret
- endfunc ;==>sockettoip
- func _skins3()
- fileinstall("d:\au3\skin\享受风格.she", @tempdir & "\1.she", 1)
- fileinstall("d:\au3\skin\skin.dll", @tempdir & "\skin.dll", 1)
- $skins = @tempdir & "\1.she"
- $dll = dllopen(@tempdir & "\skin.dll")
- dllcall($dll, "int", "skinh_attachex", "str", $skins, "str", "mhgd")
- filedelete(@tempdir & "\skin.dll")
- filedelete(@tempdir & "\1.she")
- endfunc ;==>_skins1
复制代码
|