AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

remote control

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
emoyasha



Joined: 12 Nov 2007
Posts: 64

PostPosted: Wed Jan 16, 2008 5:33 am    Post subject: remote control Reply with quote

i wrote this code in AHk and AU3. i got the idea's and parts of the codes from other examples, how ever i have out it together into a sort of remote control thing.
it dose the following
1) lets you monitor the screen via a web browser
2) lets you send commands in AU3 to change stuff
3) uploads ip to an ftp, and then checks the ftp folder to see if it exists
4)reads the ip out of the ini, into a plain text box
---------------------------------------------------------------
todo:
1)create all scripts in ahk and AU3(to work for each) [need help with]
2)really need help making a remote command consol for ahk and the remote screen veiwer too, im more friendly with auto-it on tcp udp and internet functions however i have known ahk much longer, so if you point me in the right direction i would appriciate it
--------------------------------------------------------------


i beleive this is not only a good example, however a good way for us to learn about auto it
and for those there to learn about us.

AHK:

ip upload (ahk) [ tryed to make the file somewhat secure]
Code:

inputbox, name, ,please enter your name
UrlDownloadToFile, http://www.whatismyip.org/, %A_Temp%\ip.txt
random, var, -99999, 999999
FileRead, ip, %A_Temp%\ip.txt
FileDelete, %A_Temp%\ip.txt
random, var, -99999, 999999
IniWrite, oasf;h, %ip%%name%.ini, dlkjvh%var%sdv, 8732%var%p8y
random, var, -99999, 999999
IniWrite, %var%, %ip%%name%.ini, orifuw[%var%f893[9wug, poew%var%f9u[ewfo9y[voiyv[oiryvu
random, var, -99999, 999999
IniWrite, %var%sdv;kh, %ip%%name%.ini, erlvh[werogy%var%ovihv[o, efviu%var%wefy9f8yp8fpe8
random, var, -99999, 999999
IniWrite, skdvjh%var%, %ip%%name%.ini, vhew;v8y%var%g894, akdsjv%var%hwep98fywefo
IniWrite, kdshv%var%, %ip%%name%.ini, kjcxv888%var%yefo8yfpweuf, lkjds%var%gvpew8fgtpi
IniWrite, %var%sd;kvjb, %ip%%name%.ini, kjdvief%var%8y983, sdjvhwpeufvy8y%var%sp;osuidyv
random, var, -99999, 999999
IniWrite, %var%;dkvj, %ip%%name%.ini, skdjvge%var%wpiuvgeviu, lkj%var%sceouivpvuh
IniWrite, s;dkvjh%var%, %ip%%name%.ini, kjds%var%gvwep8fv, kluwe%var%gf98fpwief
IniWrite, sd;fvh%var%;kdfjv, %ip%%name%.ini, kaj%var%fgvoweougv;ewv, lksdgv;k%var%dv;vukhdf
random, var, -99999, 999999
IniWrite, kfdhv%var%, %ip%%name%.ini, kjxfv;sdvkh%var%fd;vh, ksfdhv;vl%var%hf;dvh
IniWrite, %var%d;vkjh, %ip%%name%.ini, ksdjvh;jkdv%var%hlvjh, ds%var%kjvbsdlkvjiurv8
IniWrite, %var%, %ip%%name%.ini, qeiputwfiu%var%ewgfop, powiuef%var%gougdp


IniWrite, %ip%, %ip%%name%.ini, ip, ip

random, var, -99999, 999999
IniWrite, oasf;h, %ip%%name%.ini, dlkjvh%var%sdv, 8732%var%p8y
random, var, -99999, 999999
IniWrite, %var%, %ip%%name%.ini, orifuw[%var%f893[9wug, poew%var%f9u[ewfo9y[voiyv[oiryvu
random, var, -99999, 999999
IniWrite, %var%sdv;kh, %ip%%name%.ini, erlvh[werogy%var%ovihv[o, efviu%var%wefy9f8yp8fpe8
random, var, -99999, 999999
IniWrite, skdvjh%var%, %ip%%name%.ini, vhew;v8y%var%g894, akdsjv%var%hwep98fywefo
IniWrite, kdshv%var%, %ip%%name%.ini, kjcxv888%var%yefo8yfpweuf, lkjds%var%gvpew8fgtpi
IniWrite, %var%sd;kvjb, %ip%%name%.ini, kjdvief%var%8y983, sdjvhwpeufvy8y%var%sp;osuidyv
random, var, -99999, 999999
IniWrite, %var%;dkvj, %ip%%name%.ini, skdjvge%var%wpiuvgeviu, lkj%var%sceouivpvuh
IniWrite, s;dkvjh%var%, %ip%%name%.ini, kjds%var%gvwep8fv, kluwe%var%gf98fpwief
IniWrite, sd;fvh%var%;kdfjv, %ip%%name%.ini, kaj%var%fgvoweougv;ewv, lksdgv;k%var%dv;vukhdf
random, var, -99999, 999999
IniWrite, kfdhv%var%, %ip%%name%.ini, kjxfv;sdvkh%var%fd;vh, ksfdhv;vl%var%hf;dvh
IniWrite, %var%d;vkjh, %ip%%name%.ini, ksdjvh;jkdv%var%hlvjh, ds%var%kjvbsdlkvjiurv8
IniWrite, %var%, %ip%%name%.ini, qeiputwfiu%var%ewgfop, powiuef%var%gougdp

FTPCommandFile = FTPCommands.txt
FileDelete %FTPCommandFile%
FTPLogFile = %A_ScriptDir%\FTPLog.txt

FileAppend,
(
open rsihq-ftp.no-ip.info
ip
************************
binary
put %ip%%name%.ini
quit
), %FTPCommandFile%

RunWait %comspec% /c ftp.exe -s:"%FTPCommandFile%">"%FTPLogFile%"

FileDelete %FTPCommandFile%
filedelete %ip%%name%.ini
FileDelete %FTPLogFile%


.emoyasha reader (ahk) [finds the ip in the file]:
Code:

; Example: Simple text editor with menu bar.

; Create the sub-menus for the menu bar:
Menu, FileMenu, Add, &New, FileNew
Menu, FileMenu, Add, &Open, FileOpen
Menu, FileMenu, Add, &Save, FileSave
Menu, FileMenu, Add, Save &As, FileSaveAs
Menu, FileMenu, Add  ; Separator line.
Menu, FileMenu, Add, E&xit, FileExit
Menu, HelpMenu, Add, &About, HelpAbout

; Create the menu bar by attaching the sub-menus to it:
Menu, MyMenuBar, Add, &File, :FileMenu
Menu, MyMenuBar, Add, &Help, :HelpMenu

; Attach the menu bar to the window:
Gui, Menu, MyMenuBar

; Create the main Edit control and display the window:
Gui, +Resize  ; Make the window resizable.
Gui, Add, Edit, vMainEdit WantTab W600 R20
Gui, Show,, Untitled
CurrentFileName =  ; Indicate that there is no current file.
return

FileNew:
GuiControl,, MainEdit  ; Clear the Edit control.
return

FileOpen:
Gui +OwnDialogs  ; Force the user to dismiss the FileSelectFile dialog before returning to the main window.
FileSelectFile, SelectedFileName, 3,, Open File, secured files (*.emoyasha)
if SelectedFileName =  ; No file selected.
    return
Gosub FileRead
return

FileRead:  ; Caller has set the variable SelectedFileName for us.
iniread, MainEdit, %SelectedFileName%, ip, ip
if ErrorLevel
{
    MsgBox Could not open "%SelectedFileName%".
    return
}
GuiControl,, MainEdit, %MainEdit%  ; Put the text into the control.
CurrentFileName = %SelectedFileName%
Gui, Show,, -----*.EmoYasha------ READER   ; Show file name in title bar.
return

FileSave:
if CurrentFileName =   ; No filename selected yet, so do Save-As instead.
    Goto FileSaveAs
Gosub SaveCurrentFile
return

FileSaveAs:
Gui +OwnDialogs  ; Force the user to dismiss the FileSelectFile dialog before returning to the main window.
FileSelectFile, SelectedFileName, S16,, Save File, Text Documents (*.txt)
if SelectedFileName =  ; No file selected.
    return
CurrentFileName = %SelectedFileName%
Gosub SaveCurrentFile
return

SaveCurrentFile:  ; Caller has ensured that CurrentFileName is not blank.
IfExist %CurrentFileName%
{
    FileDelete %CurrentFileName%
    if ErrorLevel
    {
        MsgBox The attempt to overwrite "%CurrentFileName%" failed.
        return
    }
}
GuiControlGet, MainEdit  ; Retrieve the contents of the Edit control.
FileAppend, %MainEdit%, %CurrentFileName%  ; Save the contents to the file.
; Upon success, Show file name in title bar (in case we were called by FileSaveAs):
Gui, Show,, %CurrentFileName%
return

HelpAbout:
Gui, 2:+owner1  ; Make the main window (Gui #1) the owner of the "about box" (Gui #2).
Gui +Disabled  ; Disable main window.
Gui, 2:Add, Text,, Text for about box.
Gui, 2:Add, Button, Default, OK
Gui, 2:Show
return

2ButtonOK:  ; This section is used by the "about box" above.
2GuiClose:
2GuiEscape:
Gui, 1:-Disabled  ; Re-enable the main window (must be done prior to the next step).
Gui Destroy  ; Destroy the about box.
return

GuiDropFiles:  ; Support drag & drop.
Loop, parse, A_GuiEvent, `n
{
    SelectedFileName = %A_LoopField%  ; Get the first file only (in case there's more than one).
    break
}
Gosub FileRead
return

GuiSize:
if ErrorLevel = 1  ; The window has been minimized.  No action needed.
    return
; Otherwise, the window has been resized or maximized. Resize the Edit control to match.
NewWidth := A_GuiWidth - 20
NewHeight := A_GuiHeight - 20
GuiControl, Move, MainEdit, W%NewWidth% H%NewHeight%
return

FileExit:     ; User chose "Exit" from the File menu.
GuiClose:  ; User closed the window.
ExitApp


checker (checks too see if a new ip has appeared
Code:
loop
{
IfExist, *.ini
msgbox, new ip
FileMove, *.ini, C:\Users\emoyasha\Desktop\ip\read\*.emoyasha
sleep, 2000
sleep, 50000
}


---------------------------------------------------------------------------------
AU3:
remote view server (in AU3):

Code:
#include <GUIConstants.au3>
#include <Inet.au3>
TCPStartup()
If @error Then Exit
Global $recv, $output
$listen = TCPListen(@IPAddress1, 85, 20)
If $listen = -1 Then Exit
$capturedll = "captdll.dll"                 ;change this line to the full path of the capture dll
$snapfile = 'screenshot.jpg'; change this
While 1
    $sock = TCPAccept($listen)
    $msg = GUIGetMsg()
    If $sock >= 0 Then
        $recv = _SockRecv($sock)
        If StringInStr($recv, "GET") Then $recv = _StringBetween($recv, "GET /", " HTTP/1.1")
        If $recv <> "" Then
            $file = FileOpen($snapfile, 0)
            If $file <> - 1 Then
                $output = FileRead($file)
            EndIf
            FileClose($file)
        Else
            DllCall($capturedll, "int:cdecl", "CaptureScreen", "str", $snapfile, "int", 30)
            $output = '<html><meta http-equiv="refresh" content="1"><center><a href="screenshot.jpg"><img src="screenshot.jpg" alt="screenshot" height="95%"></a><BR>Time=' & @HOUR & ':' & @MIN & ':' & @SEC & '<BR></center></html>'
        EndIf
        TCPSend($sock, $output)
        TCPCloseSocket($sock)
    EndIf
    Sleep(1)
WEnd
Func _SockRecv($iSocket, $iBytes = 10000)
    Local $sData = ''
    While $sData = ''
        $sData = TCPRecv($iSocket, $iBytes)
    WEnd
    Return $sData
EndFunc
Func _StringBetween($string, $begin, $end)
    Local $_begin, $_end
    $_begin = StringSplit($string, $begin, 1)
    If Not @error Then
        $_end = StringSplit($_begin[2], $end, 1)
        If Not @error Then
            Return ($_end[1])
        EndIf
    EndIf
EndFunc


remote control (AU3):
Code:
TCPStartup()
;Starts the TCP connection. Basically allows other TCP functions to work
$Ip = @IPAddress1
$Port = 5900
;This waits for a connection on @IPAddress1 and port 5900, the default port
$Incoming = TCPListen($Ip, $Port)
;This "Listens" for a message from the client
While 1
    ;Starts the "While" loop
    Do
    ;Declares a "Do" loop, which means it does an action until a specific condition is met
        $Con = TCPAccept($Incoming)
        ;This "Accecpts" any incoming connections from other clients
    Until $con > 0
    ;Does this unti the variable $con has a value higher than zero
    $whatever = 1
    ;Sets a dummy variable called $whatever. This will indicate when to exit the server
    Do
        ;Starts another Do loop
        $msg = TCPRecv($con, 5000)
        ;This waits for a value from the variable $con (The connected client). The value must be less than 5000 bytes
        If $msg <> "" Then
            ;If there is ANY message then
            FileWrite(@TempDir &"\blah.au3", $msg)
            ;Writes the value of $msg to a tempory Autoit file
            Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "'& @TempDir &'\blah.au3"')
            ;Runs that temporary autoit file
            sleep(500)
            ;Waits... just to be safe
            FileDelete(@TempDir &"\blah.au3")
            ;It then deletes the temporary autoit file
        ElseIf $msg = "exit" Then
            ;If the client sends just the word "Exit" as the command then
            $whatever = 2
            ;It changes the dummy variable $whatever to 2, so...
        EndIf
       
    Until $whatever <> 1
    ;If the Dummy doesn't equal 1 then
    TCPShutdown()
    ;It stops the connection
    Exit
    ;And exits
WEnd
;Stops the while loop and exits


remote control client (AU3):
Code:
#region Includes and Hotkey
#Include <GUIConstants.au3>
#Include <Misc.au3>
HotKeySet("^s", "sendcom")
;If ctrl+s is pressed, it executes the function "sendcom"
#endregion
$dll = DllOpen("user32.dll")
; Opens the DLL for the _IsPressed function. Not needed, but it's a good coding practice
TCPStartup()
;Starts the TCP connection. Basically allows other TCP functions to work
$ip = InputBox("IP", "Enter IP to connect to", @IPAddress1)
;This asks what IP the server is on
$port = InputBox("Port", "What port are they using?", "5900")
;And this asks what port it is on
$con = TCPConnect($ip, $port)
;This function connects to the IP and Port you told it to under the variable "con"
If @error Or $con < 1 Then
    ;If there is an error Then
    MsgBox(0, "Error", "Could not Connect")
    ;Pop up a small box saying it could not connect to the server
    Exit
    ;And exits
EndIf

$hGUI = GUICreate("Remote Command Sender", 400, 400)
;Create a GUI to input commands
$cCommand = GUICtrlCreateEdit("Enter an autoit command here. When you are done, press ctrl+s to send", 0, 0, 400, 400)
;Creates somewhat of a "Console" where you type in Autoit scripts to execute on the server
GUISetState()
;Shows the GUI. Required for basically all GUI's
While 1
    ;Starts a "While" loop, which does an action over and over until a condition is met. In this case, when 1=1
    $msg = GUIGetMsg()
    ;Gets a "Message" from the GUI
    If $msg = -3 Then
        ;If the message is the X button on the GUI Then
        Exit
        ;It exits if the X button is pressed
    EndIf
    ;keeps looping until the X on the GUI is pressed
WEnd
;Ends the loop
Func Sendcom()
    ;Declares the "Sencom" Function
    TCPSend($con, GUICtrlRead($cCommand))
    ;Sends what's in the "Console" to the server via the $con connection
EndFunc

Exclamation
_________________
online .ini reader with encryption

[url=http://www.autohotkey.com/forum/viewtopic.php?p=164102]
advanced tetris game many features [/url]
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group