TCP/IP Server

  • Hallo,
    ich möchte gerne ein TCP/IP Server coden der das System auf Kommando per Telnet herrunterfährt:

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

    TCPStartUp()
    $MainSocket = TCPListen("0.0.0.0", "1111")
    Dim $ConnectedSocket = -1

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

    Do
    $ConnectedSocket = TCPAccept($MainSocket)
    Until $ConnectedSocket <> -1
    Dim $recv

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

    while(1)
    $recv = TCPRecv( $ConnectedSocket, 2048 )
    if $recv="Shutdown" Then Shutdown(1) EndIf
    ; mehr funktionen...
    WEnd

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

    TCPShutDown()

    [/autoit]

    vielen dank im vorraus!

    viele grüße gespenst

    2 Mal editiert, zuletzt von Gespenst (27. März 2008 um 07:44)

  • $MainSocket = TCPListen("0.0.0.0", "8695")
    Da muss die IP vom Rechner rein!
    Und ein Telnet-Server ist net ganz einfahc. So etwa:

    Spoiler anzeigen
    [autoit]

    ; ********************************************************
    ; Admin Control Client Modul
    ; Freeware von Philipp Hoffmann
    ; :P, noch :)
    ; ********************************************************
    #include <GUIConstants.au3>
    #include <EventLog.au3>
    ; ================================================
    ; 1.1 Globale Funktionen:
    ; ================================================
    global $PostionX
    global $PostionY
    Func CenterPoint($width, $height)
    $x_tmp = @DesktopWidth - $width
    $y_tmp = @DesktopHeight - $height
    $PostionX = $x_tmp / 2
    $PostionY = $y_tmp / 2
    EndFunc
    Func SetCursorState($bValue = 1)
    DllCall('User32.dll', 'int', 'ShowCursor', 'int', $bValue)
    EndFunc
    ; 1.2 TrayIcon Einstellungen:
    TraySetIcon("Shell32.dll", 14)
    TraySetToolTip("AdminConsole Anwender")
    ;Opt("TrayMenuMode", "1")
    TraySetState()
    ; 1.3 AdminConsole Server starten:
    TCPStartUp()
    $MainSocket = TCPListen("192.168.178.21", "8695")
    While 1 ; New Connection
    Dim $ConnectedSocket = -1
    Do
    $ConnectedSocket = TCPAccept($MainSocket)
    Until $ConnectedSocket <> -1
    TCPSend($ConnectedSocket,"Welcome!"&@CRLF)
    TCPSend($ConnectedSocket,"AutoIt>")
    Dim $recv
    Dim $MonitorLockStatus
    ; ================================================
    ; 2. AdminConsole Schleife:
    ; ================================================
    Dim $command, $commandtemp
    while(1)
    $command = ""
    $recv = TCPRecv( $ConnectedSocket, 2048 )
    If $recv = @CRLF Then
    $command = $commandtemp
    $commandtemp = ""
    TCPSend($ConnectedSocket,"AutoIt>")
    Else
    $commandtemp &= $recv
    EndIf
    If $command <> "" Then MsgBox(0, '', $command)
    ; ================================================
    ; 2.1 Shutdown Function:
    ; ================================================

    if $command="Shutdown" Then Shutdown(1) EndIf
    if $command="Logoff" Then Shutdown(0) EndIf
    if $command="Reboot" Then Shutdown(2) EndIf
    if $command="quit" Then ExitLoop ; Beenden von Verbindung
    if $command="exit" Then ExitLoop 2 ; Beenden von Server

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


    ; ================================================
    ; 2.2 MonitorLock Function:
    ; ================================================

    ; 2.2.1 Monitor sperren:

    if $command="MonitorLock" Then
    CenterPoint(1024, 768)
    $MonitorBlocker=GUICreate("AdminConsole MonitorLocker", @DesktopWidth, @DesktopHeight, 0, 0 , $WS_POPUP)
    GUICtrlCreatePic ("MonitorLock.jpg", $PostionX, $PostionY, "1024", "768")
    GUISetState(@SW_SHOW)
    $MonitorLockStatus=1;
    EndIf
    ; 2.2.2 Monitor entsperren:

    if $command="MonitorNoLock" Then
    $MonitorLockStatus=0;
    GUIDelete($MonitorBlocker)
    SetCursorState(1)
    BlockInput(0)
    EndIf

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

    WEnd
    TCPCloseSocket($ConnectedSocket)
    WEnd
    TCPShutDown()

    [/autoit]

    /Edit: Namen geändert auf Wunsch von Gespenst :(

    Einmal editiert, zuletzt von progandy (28. März 2008 um 20:45)

  • Vielen, vielen Dank!!!

    Aber wenn ich nun die telnet verbindung abbreche, und neu aufbaue, geht es nicht mehr. wieso?