Jump to content

Send a message through telnet


MobilAdmin
 Share

Recommended Posts

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.

Link to comment
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
Link to comment
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
Link to comment
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.

Link to comment
Share on other sites

  • 6 years later...

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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...