MobilAdmin

Send a message through telnet

11 posts in this topic

I have a paging server that can send out pages through telnet. I've been trying to figure out just how to do this with autoit, but have had no luck. I just need very simple commands. The process through the command line is this...

>telnet server.company.net 444

### Company SNPP Gateway Ready

>page #######

Pager ID Accepted

>mess "Message to be sent"

### Message Ok

>send

### Message Sent Successfully

I have tried the TCP commands with no success. Any help would be greatly appreciated. Thank you.

Share this post


Link to post
Share on other sites



This is off the top of my head. May not be correct, but it shows the principle of telnet.

TCPStartup()

$ip = TCPNameToIP("server.company.net")

$socket = TCPConnect($ip, 444)
$var = _WaitForInput() ; $var contains ### Company SNPP Gateway Ready
TCPSend($socket, "page ######")
$var = _WaitForInput() ; Pager ID Accepted
TCPSend($socket, "mess ""Message to be sent""")
$var = _WaitForInput() ; ### Message Ok
TCPSend($socket, "send")
$var = _WaitForInput() ; ### Message Sent Succesfully

Func _WaitForInput()
   While 1
     $data = TCPRecv($socket, 512)
     If $data <> "" Then Return $data
   Wend
EndFunc

Share this post


Link to post
Share on other sites

I have tried the suggested script and the execution hangs. I'm not sure where to go from here. Thanks for the help.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This is off the top of my head. May not be correct.

Do the first 3 line work for you? Do some debugging.

Edited by Manadar

Share this post


Link to post
Share on other sites

The connection is not being made at all. I'm new to this program and I'm not sure how to debug a script like this. I do know that the connection is not there. I just copied and pasted, then adjusted the details. I'm at a loss.

Share this post


Link to post
Share on other sites

I believe that its hanging because its not getting any data back to move onto the next line of the code. I can use telnet to do this and it works fine. What I had originally wrote is exactly what I see on the screen. Where to go from here?

Share this post


Link to post
Share on other sites

Try this for debugging:

TCPStartup()

$ip = TCPNameToIP("server.company.net")

$socket = TCPConnect($ip, 444)
$var = _WaitForInput() ; $var contains ### Company SNPP Gateway Ready
TCPSend($socket, "page ######")
$var = _WaitForInput() ; Pager ID Accepted
TCPSend($socket, "mess ""Message to be sent""")
$var = _WaitForInput() ; ### Message Ok
TCPSend($socket, "send")
$var = _WaitForInput() ; ### Message Sent Succesfully

Func _WaitForInput()
   Sleep(1000)
EndFunc

Share this post


Link to post
Share on other sites

The scripted runs through to the end, but the message doesn't go out.

Share this post


Link to post
Share on other sites

It's something that you are doing wrong. I have tried all sorts of setups, and can safely confirm that this works in establishing a telnet connection.

I've even made a small script to let you learn a little more about the TCP functions:

Local $packet, $data, $ip, $socket

$packet =   "GET / HTTP/1.1" & @CRLF & _
            "Host: www.google.com" & @CRLF & _
            @CRLF

TCPStartup()

$ip = TCPNameToIP("www.google.com")

$socket = TCPConnect($ip, 80)
TCPSend($socket, $packet)

While 1
    $data = TCPRecv($socket, 512)
    If ($data <> "") Then
        ConsoleWrite($data)
        ExitLoop
    EndIf
    Sleep(50)
WEnd

For more help, post more information: What you are doing, what is the telnet server, what packets are going out, what are the return variables of the functions etc. I'm out for a while.

Share this post


Link to post
Share on other sites

Was same problem...

Just add @CRLF to all tcpsend messages.

 

TCPStartup()
$var = _WaitForInput()
$ip = TCPNameToIP("***************")
$var = _WaitForInput() ;
$socket = TCPConnect($ip, 4444)
While 1
    $data = TCPRecv($socket, 512)
    If ($data <> "") Then
        ConsoleWrite($data)
        ExitLoop
    EndIf
    Sleep(50)
WEnd


TCPSend($socket, "PAGE *************"&@CRLF)
ConsoleWrite("PAGE *************"&@CRLF)
While 1
    $data = TCPRecv($socket, 512)
    If ($data <> "") Then
        ConsoleWrite($data)
        ExitLoop
    EndIf
    Sleep(50)
WEnd
TCPSend($socket, "MESS 1234567"&@CRLF)
ConsoleWrite("MESS 1234567"&@CRLF)
While 1
    $data = TCPRecv($socket, 512)
    If ($data <> "") Then
        ConsoleWrite($data)
        ExitLoop
    EndIf
    Sleep(50)
WEnd
TCPSend($socket, "SEND"&@CRLF)
ConsoleWrite("SEND"&@CRLF)
While 1
    $data = TCPRecv($socket, 512)
    If ($data <> "") Then
        ConsoleWrite($data)
        ExitLoop
    EndIf
    Sleep(50)
WEnd
TCPSend($socket, "QUIT"&@CRLF)
ConsoleWrite("QUIT"&@CRLF)
While 1
    $data = TCPRecv($socket, 512)
    If ($data <> "") Then
        ConsoleWrite($data)
        ExitLoop
    EndIf
    Sleep(50)
WEnd

TCPShutdown() ; Close the TCP service.

Func _WaitForInput()
   Sleep(3000)
EndFunc

 

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