Jump to content
Sign in to follow this  
SpookMeister

Trouble with TCPConnect for telnet

Recommended Posts

SpookMeister

Hi guys,

I'm having some trouble with using the built in network functions. Specifically, I am trying to connect to a device via telnet, send login information then issue a command.

Here's the code sample I am using:

Global $socket = -1
$delay = 500
$ip = "192.168.100.101"
$timer = TimerInit()
TCPStartup()
$socket = TCPConnect($ip, 23)
If @error Then
    MsgBox(0, "Error", "Connection Failed" & @CRLF & "Error: " & @error)
    TCPShutdown()
    Exit
EndIf

Sleep($delay)
_MySend("username")
Sleep($delay)
_MySend("password")
Sleep($delay)
_MySend("command to do what I want")

TCPCloseSocket($socket)
TCPShutdown()

Func _MySend($msg)
    TCPSend($socket, $msg & @LF)
    If @error Then
        ConsoleWrite("Error Sending Text" & @CRLF)
    Else
        ConsoleWrite($msg & " : sent at " & Round(TimerDiff($timer) / 1000, 2) & " sec" & @CRLF)
    EndIf
EndFunc   ;==>_MySend

Can anyone see what I'm doing wrong?

I've played around with assorted delays between sends, with using @LF vs @CR vs @CRLF vs chr(10) vs chr(13) and am not having any luck.

-Spook


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites
jvanegmond

Hey SpookMeister,

usually when I run into these kind of problems I use a packet scanner like WireShark or WPE Pro 0.9x.

Also, your problem might just be caused by the fact that you're not willing to receive the data back. Try and TCPRecv the data and, for debugging purposes, write the data that you receive to the console or something.

Links to..

Wireshark: http://www.wireshark.org/

Greetings,

Manadar

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  

×