Sign in to follow this  
Followers 0
dillonlim

Poor man's telnet server

1 post in this topic

#1 ·  Posted (edited)

Wrote this a part of a framework for a friend's project. I've only tested it on x86 WinXP. It only works with Microsoft telnet client. It WILL fail with PuTTY, any third party telnet client and any flavor Linux/Unix telnet client.

$port = "666"

TCPStartup ()

$GIT = TCPListen(@IPAddress1, $port)
If $GIT = -1 Then
    MsgBox(0, "Error", "Unable to start server on " & $port)
    Exit
EndIf

While 1
Do
    $GOT = TCPAccept($GIT)
Until $GOT <> -1
TCPSend($GOT, "Command? ")

    While 1

        $HAS = TCPRecv($GOT, 4096)
        $CHKVAR = StringLen($HAS)
    
        If $CHKVAR > 0 Then
            Local $HASSING = ""
                Do
                    $HASSING &= TCPRecv($GOT, 4096)
                    $CHKCHAR = StringRight($HASSING, 1)
                Until $CHKCHAR = ";"

            $HASSAN = StringTrimRight($HASSING, 1)
            $CMSG = $HAS & $HASSAN
            TCPSend($GOT, @CRLF & "Command? ")
            If StringLower($CMSG) <> "exit" Then
                TrayTip("i haz a msg", $CMSG, 5, 0)
            Else
                TrayTip("", "", 5, 0)
            EndIf

            Select
            Case StringLower($CMSG) = "exit"
                TCPSend($GOT, "Goodbye!")
                TCPCloseSocket($GOT)
                ExitLoop
            Case StringLower($CMSG) = "close"
                Send("!{F4}")
            Case StringLower($CMSG) = "return"
                Send("{ENTER}")
            Case StringLeft(StringLower($CMSG), 4) = "send"
                $TRIMMER = StringTrimLeft($CMSG, 5)
                Send($TRIMMER)
                Send("{ENTER}")
            Case StringLeft(StringLower($CMSG), 2) = "go"
                $TRIMMER = StringTrimLeft($CMSG, 3)
                ShellExecute($TRIMMER)
            EndSelect
        EndIf
    WEnd
WEnd
TCPShutDown()
Edited by dillonlim

Share this post


Link to post
Share on other sites



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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0