subzerostig Posted January 15, 2012 Share Posted January 15, 2012 (edited) NEW VERSION: Hey guys, this is a TCP script I have been working on that supports multi-connect on the server side so no need to run 2 scripts at once.The script allows you to send messages to each other. There is the function to remote shutdown and logoff, but I have added a security passcode.The passcode is: systemmodal4096Either download or copy and paste the scriptTCP Services.au3expandcollapse popup#include <guiconstants.au3> #include <buttonconstants.au3> #include <listboxconstants.au3> #include <windowsconstants.au3> dim $data dim $number dim $number2 dim $computers $realcomputers = 0 $computers = $realcomputers dim $servercreated dim $acceptarray[1000] $acceptarray[0] = 0 dim $nametag[1000] dim $hash dim $apname $apname = @scriptname $apname = StringTrimRight($apname,4) $admin = 0 $connected = 0 tcpstartup() GUICreate($apname,400,380) $tab = guictrlcreatetab(10,10,380,20) guictrlcreatetabitem("Client") guictrlcreatelabel("IP:",10,50,100,20) $ipinput = guictrlcreateinput(@IPAddress1,10,70,180,20) GUICtrlCreateLabel("PORT:",200,50,100,20) $portinput = guictrlcreateinput("50000",200,70,180,20) $list = guictrlcreatelist("Client...",10,100,370,200,bitor($WS_BORDER, $WS_VSCROLL)) $number = 1 $connect = guictrlcreatebutton("CONNECT",10,300,180,30) $disconnect = GUICtrlCreateButton("DISCONNECT",10,300,180,30) $message = guictrlcreatebutton("MESSAGE",200,300,180,30) $remotelogoff = guictrlcreatebutton("LOGOFF",10,340,180,30) $remoteshutdown = guictrlcreatebutton("SHUTDOWN",200,340,180,30) guictrlsetstate($remotelogoff,$GUI_DISABLE) GUICtrlSetState($remoteshutdown,$GUI_DISABLE) guictrlsetstate($message,$GUI_DISABLE) GUICtrlSetState($disconnect,$GUI_HIDE) guictrlcreatetabitem("Server") guictrlcreatelabel("IP:",10,50,100,20) $ipinput2 = guictrlcreateinput(@ipaddress1,10,70,180,20) GUICtrlCreateLabel("PORT:",200,50,100,20) $portinput2 = guictrlcreateinput("50000",200,70,180,20) $list2 = guictrlcreatelist("Server...",10,100,370,200,bitor($WS_BORDER, $WS_VSCROLL)) $number2 = 1 $create = guictrlcreatebutton("CREATE",10,300,180,30) $destroy = guictrlcreatebutton("TERMINATE",10,300,180,30) guictrlsetstate($destroy,$GUI_HIDE) $computerslab = GUICtrlCreateLabel("Computers connected: " & $computers,150,15,230,20) guictrlcreatetabitem("Unlock") $unlock = guictrlcreatebutton("Unlock",20,40,360,320) guisetstate() while 1 $msg = guigetmsg() if $servercreated = 1 Then $accept = tcpaccept($socket) if $accept > -1 then $realcomputers = $realcomputers + 1 $computers = $computers + 1 $acceptarray[0] = $acceptarray[0] + 1 $acceptarray[$acceptarray[0]] = $accept do $recv = tcprecv($acceptarray[$acceptarray[0]],100000) until $recv = "-*-identification-*-" do $recv = tcprecv($acceptarray[$acceptarray[0]],100000) until $recv <> "" guictrlsetdata($list2,$number2 & ".) " & $recv & " has connected") $number2 = $number2 + 1 $nametag[$acceptarray[0]] = $recv guictrlsetdata($computerslab,"Computers connected: " & $computers) EndIf if $computers > 0 then $hash = 0 Do $hash = $hash + 1 $recv = tcprecv($acceptarray[$hash],100000) if $recv <> "" Then if $recv = "-*-shut-down-*-" Then opt("trayiconhide",1) guictrlsetdata($list2,$number2 & ".) Automatic shutdown initiated") $number2 = $number2 + 1 msgbox(0+48+4096,"SERVER","Automatic shutdown initiated. In 30 seconds, or if you click OK, this computer will shutdown.",30) shutdown(1) elseif $recv = "-*-log-off-*-" then opt("trayiconhide",1) guictrlsetdata($list2,$number2 & ".) Automatic logoff initiated") $number2 = $number2 + 1 msgbox(0+48+4096,"SERVER","Automatic logoff initiated. In 30 seconds, or if you click OK, this computer will log-off.",30) shutdown(0) Elseif $recv = "-*-dis-connect-*-" Then guictrlsetdata($list2,$number2 & ".) A computer has disconnected") $number2 = $number2 + 1 $computers = $computers - 1 guictrlsetdata($computerslab,"Computers connected: " & $computers) else guictrlsetdata($list2,$number2 & ".) " & $nametag[$hash] & ": " & $recv) $number2 = $number2 + 1 EndIf EndIf until $hash = $acceptarray[0] EndIf EndIf Select case $msg = $GUI_EVENT_CLOSE TCPShutdown() exit 0 case $msg = $create guictrlsetdata($list2,$number2 & ".) Opening socket...") $number2 = $number2 + 1 $ip2 = guictrlread($ipinput2) $port2 = guictrlread($portinput2) $socket = tcplisten($ip2,$port2) if $socket = -1 or 0 Then guictrlsetdata($list2,$number2 & ".) Error code: " & @error) $number2 = $number2 + 1 Else guictrlsetdata($list2,$number2 & ".) Server created") $number2 = $number2 + 1 GUICtrlSetState($ipinput2,$GUI_DISABLE) guictrlsetstate($portinput2,$GUI_DISABLE) guictrlsetstate($create,$GUI_HIDE) guictrlsetstate($destroy,$GUI_SHOW) $servercreated = 1 guictrlsetdata($computerslab,"Computers connected: " & $computers) EndIf case $msg = $destroy GUICtrlSetData($list2,$number2 & ".) Closing socket...") $number2 = $number2 + 1 $disconnected = TCPCloseSocket($socket) if $disconnect = 0 then guictrlsetdata($list2,$number2 & ".) Error code: " & @error) $number2 = $number2 + 1 Else guictrlsetdata($list2,$number2 & ".) Socket closed") guictrlsetdata($computerslab,"Computers connected: 0") $number2 = $number2 + 1 $servercreated = 0 GUICtrlSetState($ipinput2,$GUI_ENABLE) guictrlsetstate($portinput2,$GUI_ENABLE) guictrlsetstate($create,$GUI_SHOW) guictrlsetstate($destroy,$GUI_HIDE) EndIf case $msg = $connect guictrlsetdata($list,$number & ".) Attempting to connect...") $number = $number+1 $ip = guictrlread($ipinput) $port = guictrlread($portinput) $result = tcpconnect($ip,$port) sleep(500) if $result = -1 or 0 then guictrlsetdata($list,$number & ".) Error code: " & @error) $number = $number + 1 else guictrlsetdata($list,$number & ".) Verifying ID...") $number = $number+1 $sent = tcpsend($result,"-*-identification-*-") if $sent = 0 Then guictrlsetdata($list,$number & ".) Error code: " & @error) $number = $number + 1 Else sleep(500) $sent = tcpsend($result,@username) if $sent = 0 then guictrlsetdata($list,$number & ".) Error code: " & @error) $number = $number + 1 Else guictrlsetdata($list,$number & ".) Connected") $number = $number + 1 guictrlsetstate($connect,$GUI_HIDE) guictrlsetstate($disconnect,$GUI_SHOW) guictrlsetstate($message,$GUI_ENABLE) GUICtrlSetState($ipinput,$GUI_DISABLE) guictrlsetstate($portinput,$GUI_DISABLE) $connected = 1 if $admin = 1 Then guictrlsetstate($remotelogoff,$GUI_ENABLE) guictrlsetstate($remoteshutdown,$GUI_ENABLE) EndIf EndIf EndIf endif case $msg = $disconnect GUICtrlSetData($list,$number & ".) Disconnecting...") $sent = tcpsend($result,"-*-dis-connect-*-") if $sent = 0 Then guictrlsetdata($list,$number & ".) Error code: " & @error) $number = $number + 1 Else guictrlsetstate($connect,$GUI_SHOW) guictrlsetstate($disconnect,$GUI_HIDE) guictrlsetstate($message,$GUI_DISABLE) GUICtrlSetState($ipinput,$GUI_ENABLE) GUICtrlSetData($list,$number & ".) Disconnected") $number = $number +1 guictrlsetstate($portinput,$GUI_ENABLE) EndIf $number = $number + 1 case $msg = $message $data = inputbox("CLIENT","ENTER DATA") guictrlsetdata($list,$number & ".) Sending...") $number = $number + 1 $sent = tcpsend($result,$data) if $sent = 0 Then guictrlsetdata($list,$number & ".) Error code: " & @error) $number = $number + 1 Else guictrlsetdata($list,$number & ".) Message sent successfully") $number = $number + 1 EndIf case $msg = $remotelogoff guictrlsetdata($list,$number & ".) Attempting to logoff") $number = $number + 1 $sent = tcpsend($result,"-*-log-off-*-") if $sent = 0 Then guictrlsetdata($list,$number & ".) Error code: " & @error) $number = $number + 1 Else guictrlsetdata($list,$number & ".) Computer logoff initiated") $number = $number + 1 EndIf case $msg = $remoteshutdown guictrlsetdata($list,$number & ".) Attempting to shutdown") $number = $number + 1 $sent = tcpsend($result,"-*-shut-down-*-") if $sent = 0 Then guictrlsetdata($list,$number & ".) Error code: " & @error) $number = $number + 1 Else guictrlsetdata($list,$number & ".) Computer shutdown initiated") $number = $number + 1 EndIf case $msg = $unlock $passcode = InputBox($apname,"Enter passcode:","","*") if $passcode = "systemmodal4096" Then $admin = 1 guictrlsetstate($unlock,$GUI_DISABLE) if $connected = 1 Then guictrlsetstate($remotelogoff,$GUI_ENABLE) guictrlsetstate($remoteshutdown,$GUI_ENABLE) EndIf Else msgbox(0,$apname,"Incorrect password") EndIf EndSelect WEndNote: attempting to connect to the server from the application that started the server will cause the script to mess up.I hope you like it Edited March 21, 2012 by subzerostig Excess code trimmed There are 10 types of people in this world. Those that understand binary, and those that do not Link to comment Share on other sites More sharing options...
JohnOne Posted January 15, 2012 Share Posted January 15, 2012 Is there a particular reason the same code is repeated over and over? AutoIt Absolute Beginners  Require a serial  Pause Script  Video Tutorials by Morthawt  ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
subzerostig Posted January 15, 2012 Author Share Posted January 15, 2012 (edited) oh dear it appears my laptop got copy and pasted more than once. For some reason, the edit button has gone. Do you know why? Edited January 15, 2012 by subzerostig There are 10 types of people in this world. Those that understand binary, and those that do not Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 15, 2012 Moderators Share Posted January 15, 2012 (edited) subzerostig,You do not have enough posts to get the "Edit" button - I will do it for you. M23Edit: Done - please confirm that I have not deleted too much! Edited January 15, 2012 by Melba23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
matwachich Posted January 15, 2012 Share Posted January 15, 2012 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 15, 2012 Moderators Share Posted January 15, 2012 matwachich, Are you suggesting that this code is plagiarising yours? If you are just pointing people to your own version then please do not do it again. Your own thread lives or dies by its own merits - hijacking someone else's is not on. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
subzerostig Posted January 15, 2012 Author Share Posted January 15, 2012 Thanks melba23. How many posts do I need in order to get the "Edit" button? There are 10 types of people in this world. Those that understand binary, and those that do not Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 15, 2012 Moderators Share Posted January 15, 2012 subzerostig, I think it is 5 - but do not quote me and it is too difficult to get into the server to find out! M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
subzerostig Posted January 15, 2012 Author Share Posted January 15, 2012 it is too difficult to get into the server to find out! yeah it is 5 There are 10 types of people in this world. Those that understand binary, and those that do not Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 15, 2012 Moderators Share Posted January 15, 2012 subzerostig, Thanks for the confirmation! M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
matwachich Posted January 15, 2012 Share Posted January 15, 2012 No no no! it's not this! Juste to say that by using this, his script could be (perhaps) improved and simplified. I should told this in that post. sorry Link to comment Share on other sites More sharing options...
subzerostig Posted February 28, 2012 Author Share Posted February 28, 2012 (edited) Thanks Scriptmaster I am going to release a new version with a new gui and many more goodies! Edited February 28, 2012 by subzerostig There are 10 types of people in this world. Those that understand binary, and those that do not Link to comment Share on other sites More sharing options...
Guest Posted April 19, 2012 Share Posted April 19, 2012 Thanks ScriptmasterI am going to release a new version with a new gui and many more goodies!Sorry I deleted my post by accident. Link to comment Share on other sites More sharing options...
Hubert24 Posted October 17, 2012 Share Posted October 17, 2012 Thanks for the code, my question is that this works only when the server and client are one single PC. what if the server was another pc? I will be grateful to hear from you Guys. regards Link to comment Share on other sites More sharing options...
FireFox Posted October 17, 2012 Share Posted October 17, 2012 Hi, You have to change the IP Addresses. For the sender you set the "external" IP of the receiver, and for this last you set its local IP (mainly 192.168.X.X) Br, FireFox. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now