Sign in to follow this  
Followers 0
ttleser

Need help with Telnet script

4 posts in this topic

Need a little help here. I manage 3 teamspeak servers, each housed at a different location. Teamspeak is a software that you can download and allow you to talk to others, similiar to ventrilo or skype. Like I said, I manage 3 teamspeak servers for my community. I have what I call a master Teamspeak server, the other 2 servers are slaves. Every night, I copy over the master database file to the slave servers, this allows me to keep all the userIDs from the master and keep the slaves mirrored of the master, kinda a poor synchronization. Using DOS telnet, I can connect to the other servers and change the server name and description. You just open a cmd prompt and type "telnet IP_Of_Server 51234" (51234 is the port the server runs on). Once you do that you'll get a reply of "[TS]". Then you'll enter commands, being careful not to hit backspace as the command won't work, gotta be careful and type it right first time. Each command you enter will either return a OK or ERROR. Here's a screenshot of an example of what I would type:

Posted Image

I've created a script that'll log into the server and change the settings automatically. The script will evolve into more things, like copying the database from the master, shutting down the server, starting up the server and changing the settings. But for right now I want to get the script working with a test server and just changing the settings. Below is the script that I used from some of the others here on the forums that appeared to have gotten the script to talk to a telnet session. I was able to get it to connect and the script will return with a msgbox that says "[TS]", which tells me it started the conversation. The script hits the next send, which is "sel 8767", I've got a while 1 loop setup that'll wait for a reply of "OK", if it's OK then it'll display a msgbox telling me it was good. I don't get a msgbox. I've modified the script so that it'll just send the commands, but when I check the server, none of the options has changed. I've removed the while 1 loop and just had to do a TCPRecv and display the response to a msgbox, but the response is blank. I'm guessing it either didn't get a response or that it simply returned blank.

Any thoughts??

You can find teamspeak here > www.goteamspeak.com

It's easy to setup a server, just download the server program (not beta) and install it. It'll give you a box telling you what the default ID and PWs are. Copy them down and open up a cmd prompt and connect to it. Just substitute my ID and PW for yours (superadmin). You can type "help" and it'll give you a list of commands.

;$szServerPC = "localhost"
; Set $szIPADDRESS to wherever the SERVER is. We will change a PC name into an IP Address
$szIPADDRESS = "127.0.0.1"
$nPORT = 51234


; Initialize a variable to represent a connection
;==============================================
Dim $ConnectedSocket = -1


;Attempt to connect to SERVER at its IP and PORT 51234
;=======================================================
;$ConnectedSocket = TCPConnect($szIPADDRESS,$nPORT)
TCPStartup()
$ConnectedSocket = TCPConnect($szIPADDRESS, $nPort)

Dim $szData

; If there is an error... show it
If @error Then
    MsgBox(4112,"Error","TCPConnect failed with WSA error: " & @error)
; If there is no error loop an inputbox for data
;   to send to the SERVER.
Else
;Loop forever asking for data to send to the SERVER

;       TCPSend($ConnectedSocket,"")
        $recv = TCPRecv( $ConnectedSocket, 2048)
        msgbox(0,"note",$recv)
        TCPSend($ConnectedSocket,"sel 8767")

While 1
    $data = TCPRecv( $ConnectedSocket, 2048)
    If $data = "OK" Then    
        msgbox(0,"Successful",$data)
    ElseIf $data <> "" Then
        MsgBox(0,"Received Packet", $data)
    EndIf
WEnd
        
    While 1
    ; InputBox for data to transmit
        $szData = InputBox("Data for Server",@LF & @LF & "Enter data to transmit to the SERVER:")
        
    ; If they cancel the InputBox or leave it blank we exit our forever loop
        If @error Or $szData = "" Then ExitLoop
        
    ; We should have data in $szData... lets attempt to send it through our connected socket.
        TCPSend($ConnectedSocket,$szData)
        $recv = TCPRecv( $ConnectedSocket, 2048)
        msgbox(0,"note",$recv)
        
    ; If the send failed with @error then the socket has disconnected
    ;----------------------------------------------------------------
        If @error Then ExitLoop
    WEnd
EndIf

Share this post


Link to post
Share on other sites



This will get you going.. :)

$localhost = "127.0.0.1"
$port = "51234"

TCPStartup()
$Socket = TCPConnect($localhost, $port)
If $Socket = -1 Then
    MsgBox(0, "", "Error")
    Exit
EndIf

$Connected = True
$Status = 0
While $Connected
    $recieved = _Recieve($Socket)
    If StringInStr($recieved, "[TS]") Then
        TCPSend($Socket, "sel 8767" & @CRLF)
    Else
        MsgBox(48, "Error", $recieved)
        _AutoItExit()
    EndIf
    $recieved = _Recieve($Socket)
    If StringInStr($recieved, "OK") Then
        TCPSend($Socket, "slogin superadmin ho4num" & @CRLF)
    Else
        MsgBox(48, "Error", $recieved)
        _AutoItExit()
    EndIf
    $recieved = _Recieve($Socket)
    If StringInStr($recieved, "OK") Then
        TCPSend($Socket, "serverset server_name New_Server" & @CRLF)
    Else
        MsgBox(48, "Error", $recieved)
        _AutoItExit()
    EndIf
    $recieved = _Recieve($Socket)
    If StringInStr($recieved, "OK") Then
        TCPSend($Socket, "quit" & @CRLF)
        ExitLoop
    Else
        MsgBox(48, "Error", $recieved)
        _AutoItExit()
    EndIf
    Sleep(200)
WEnd

ConsoleWrite("Normal Closing" & @LF)
_AutoItExit()

Func _Recieve(ByRef $Socket)
    $timer = TimerInit()
    Local $recieving = ""
    ConsoleWrite($recieving & "Recieving")
    While $recieving = ""
        $recieving = TCPRecv($Socket, 2048)
        Sleep(100)
        ConsoleWrite(".")
        If TimerDiff($timer) > 30000 Then ; 30 Seconds timeout
            MsgBox(48, "Error", "Timeout!")
            _AutoItExit()
        EndIf
    WEnd
    ConsoleWrite(@LF)
    ConsoleWrite($recieving & @LF)
    Return $recieving
EndFunc   ;==>_Recieve


Func _AutoItExit()
    TCPShutdown()
    Exit
EndFunc   ;==>_AutoItExit

Share this post


Link to post
Share on other sites

LOL, Looking over your script I found that I missed something stupid with mine.... DUH!!!! I forget to do @CRLF (Enter key basically). So Stupid. My script worked after that modification. Now I just need to modify it to allow for more features.. :)

Thanks for the post, I'll examine your script and see what's different than mine.

Share this post


Link to post
Share on other sites

Need a little help here. I manage 3 teamspeak servers, each housed at a different location. Teamspeak is a software that you can download and allow you to talk to others, similiar to ventrilo or skype. Like I said, I manage 3 teamspeak servers for my community. I have what I call a master Teamspeak server, the other 2 servers are slaves. Every night, I copy over the master database file to the slave servers, this allows me to keep all the userIDs from the master and keep the slaves mirrored of the master, kinda a poor synchronization. Using DOS telnet, I can connect to the other servers and change the server name and description. You just open a cmd prompt and type "telnet IP_Of_Server 51234" (51234 is the port the server runs on). Once you do that you'll get a reply of "[TS]". Then you'll enter commands, being careful not to hit backspace as the command won't work, gotta be careful and type it right first time. Each command you enter will either return a OK or ERROR. Here's a screenshot of an example of what I would type:

Posted Image

I've created a script that'll log into the server and change the settings automatically. The script will evolve into more things, like copying the database from the master, shutting down the server, starting up the server and changing the settings. But for right now I want to get the script working with a test server and just changing the settings. Below is the script that I used from some of the others here on the forums that appeared to have gotten the script to talk to a telnet session. I was able to get it to connect and the script will return with a msgbox that says "[TS]", which tells me it started the conversation. The script hits the next send, which is "sel 8767", I've got a while 1 loop setup that'll wait for a reply of "OK", if it's OK then it'll display a msgbox telling me it was good. I don't get a msgbox. I've modified the script so that it'll just send the commands, but when I check the server, none of the options has changed. I've removed the while 1 loop and just had to do a TCPRecv and display the response to a msgbox, but the response is blank. I'm guessing it either didn't get a response or that it simply returned blank.

Any thoughts??

You can find teamspeak here > www.goteamspeak.com

It's easy to setup a server, just download the server program (not beta) and install it. It'll give you a box telling you what the default ID and PWs are. Copy them down and open up a cmd prompt and connect to it. Just substitute my ID and PW for yours (superadmin). You can type "help" and it'll give you a list of commands.

;$szServerPC = "localhost"
; Set $szIPADDRESS to wherever the SERVER is. We will change a PC name into an IP Address
$szIPADDRESS = "127.0.0.1"
$nPORT = 51234
; Initialize a variable to represent a connection
;==============================================
Dim $ConnectedSocket = -1
;Attempt to connect to SERVER at its IP and PORT 51234
;=======================================================
;$ConnectedSocket = TCPConnect($szIPADDRESS,$nPORT)
TCPStartup()
$ConnectedSocket = TCPConnect($szIPADDRESS, $nPort)

Dim $szData

; If there is an error... show it
If @error Then
    MsgBox(4112,"Error","TCPConnect failed with WSA error: " & @error)
; If there is no error loop an inputbox for data
;   to send to the SERVER.
Else
;Loop forever asking for data to send to the SERVER

;       TCPSend($ConnectedSocket,"")
        $recv = TCPRecv( $ConnectedSocket, 2048)
        msgbox(0,"note",$recv)
        TCPSend($ConnectedSocket,"sel 8767")

While 1
    $data = TCPRecv( $ConnectedSocket, 2048)
    If $data = "OK" Then    
        msgbox(0,"Successful",$data)
    ElseIf $data <> "" Then
        MsgBox(0,"Received Packet", $data)
    EndIf
WEnd
        
    While 1
    ; InputBox for data to transmit
        $szData = InputBox("Data for Server",@LF & @LF & "Enter data to transmit to the SERVER:")
        
    ; If they cancel the InputBox or leave it blank we exit our forever loop
        If @error Or $szData = "" Then ExitLoop
        
    ; We should have data in $szData... lets attempt to send it through our connected socket.
        TCPSend($ConnectedSocket,$szData)
        $recv = TCPRecv( $ConnectedSocket, 2048)
        msgbox(0,"note",$recv)
        
    ; If the send failed with @error then the socket has disconnected
    ;----------------------------------------------------------------
        If @error Then ExitLoop
    WEnd
EndIf
You have to tell the server to end the line also

Try your commands with the & CRLF

TCPSend($ConnectedSocket,"sel 8767" & CRLF)

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