Search code examples
tcptelnetautoit

Autoit tcp connection to server


I'm pretty new to TCP connections and very new to Autoit.

I'm trying to connect to a game server that I admin in order to receive server data (online players, chat logs, etc) and to send TelNet commands to the server if needed (Ban player, kick player, etc)

Looking at the TCP functions for Autoit, I only see a place for IP and Port information, but the server has an admin password, and I have no idea how to incorporate the password into the mix.

I would appreciate any insight into how I would go about connecting to the server and receiving data.


Solution

  • Use IP:Port to connect and then you do the communication with the server

    This is an old script I wrote to connect thru telnet to my router in order to change the IP.

    TCPStartup()
    TrayTip("Changing IP adress!", "...connecting...", 10)
    $router_IP = "192.168.1.1"
    $port = "23" ; standard telnet port
    
    $username = "admin"
    $pass = "****"
    
    
    Dim $ConnectedSocket = -1
    $ConnectedSocket = TCPConnect($router_IP, $port)
    If $ConnectedSocket = -1 Then
        TrayTip("Changing IP adress!", "Error! Cant connect!", 10)
        Sleep(3000)
        Exit
    EndIf
    TrayTip("Changing IP adress!", "Connected.", 10)
    
    $old = ""
    
                $ret = TCPSend($ConnectedSocket, $username & @LF)
                Sleep(2000)
                $ret = TCPSend($ConnectedSocket, $username & @LF)
                Sleep(2000)
                $ret = TCPSend($ConnectedSocket, $username & @LF)
                $old &= TCPRecv($ConnectedSocket, 2048)
                TrayTip("Changing IP address!", $old, 10)
                Sleep(2000)
                $ret = TCPSend($ConnectedSocket, $pass & @CRLF)
                $old &= TCPRecv($ConnectedSocket, 2048)
                TrayTip("Changing IP adress!", $old, 10)
                Sleep(2000)
                $ret = TCPSend($ConnectedSocket, "sh" & @CRLF)
                $old &= TCPRecv($ConnectedSocket, 2048)
                TrayTip("Changing IP adress!", $old, 10)
                Sleep(3000)
                $ret = TCPSend($ConnectedSocket, "ifconfig nas_8_35 down" & @CRLF)
                $old &= TCPRecv($ConnectedSocket, 2048)
                TrayTip("Changing IP adress!", $old, 10)
                Sleep(10000)
                $ret = TCPSend($ConnectedSocket, "ifconfig nas_8_35 up" & @CRLF)
                $old &= TCPRecv($ConnectedSocket, 2048)
                TrayTip("Changing IP adress!", $old, 10)
                Sleep(2000)
                $ret = TCPSend($ConnectedSocket, "exit" & @CRLF)
                $old &= TCPRecv($ConnectedSocket, 2048)
                TrayTip("Changing IP adress!", $old, 10)
                Sleep(2000)
                $ret = TCPSend($ConnectedSocket, "exit" & @CRLF)
                $old &= TCPRecv($ConnectedSocket, 2048)
                TrayTip("Changing IP adress!", $old, 10)
                Sleep(5000)
    

    Can't remember why I send the username 3 times thou... Also, since you are new, these are the places to start:

    Autoit for absolute beginners

    Autoit 1-2-3

    Autoit Tcp examples and scripts

    TELNET

    Good luck!