Jump to content

Recommended Posts

Posted (edited)

I want to check some DSL properties that are visible on my router Zyxel 660.

So I thought it's a good time to learn more of TCP functions in Autoit.

My test is to simulate a telnet connection with Autoit. I searched the forum but I found no examples.

I know I can use consoletelnet or make the hack of saving telnet output... but hey, have I said I want to learn more the TCP? :D

I made this attempt:

#include <GUIConstants.au3>

TCPStartup()

$router_IP = "192.168.1.10"


$GOOEY = GUICreate("Telnet client",700,400)
$edit = GUICtrlCreateEdit("",10,40,680,350,$WS_DISABLED)
$input = GUICtrlCreateInput("",10,10,300,20)
$butt = GUICtrlCreateButton("Send",320,10,80,20,$BS_DEFPUSHBUTTON)
GUISetState()



Dim $ConnectedSocket = -1
$ConnectedSocket = TCPConnect($router_IP , 23)

Dim $msg, $recv, $ret
; GUI Message Loop
;==============================================
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

;;; send part:

   If $msg = $butt Then
    $ret = TCPSend( $ConnectedSocket , GUICtrlRead($input))
    If @ERROR Or $ret < 0 Then ExitLoop
    GUICtrlSetData($input,"")
    GUICtrlSetState($input,$GUI_FOCUS)
   EndIf


;;; receive part:

    $recv = TCPRecv( $ConnectedSocket, 2048)
    If @error Then ExitLoop
    If $recv <> "" Then GUICtrlSetData($edit, " > " & $recv & @CRLF & GUICtrlRead($edit))
    ;GUICtrlSendMsg($edit, $EM_SCROLL, $SB_PAGEDOWN, 0)
    
WEnd



quit()


func quit()
    TCPCloseSocket( $ConnectedSocket )
    TCPShutdown()
    Exit
endfunc

The problem is that I get only the first answer from connection with password, and when I send it, I receive only the "********" response. I mean the password inserted is obscured. I display no more data.

So, what's wrong?

Edited by frank10
Posted

So, nobody help me?

Please give me some tips, as I need some.

For example do I need to use TCPListen to receive the data?

And is it always necessary to use TcpAccept after TcpListen?

Anyway in this case it seems to me I made a connection witn TcpConnect, so the server (the router) is already listening...

Could you try my code? You need only to change your IP router address.

TIA

Posted

http://www.autoitscript.com/forum/index.php?showtopic=20589

TCP Examples...

For example do I need to use TCPListen to receive the data?

Only if you are doing a server. Here, you are making a telnet client, so it is not necessary.

And is it always necessary to use TcpAccept after TcpListen?

For a server then use TCPAccept.

Only for servers!!!:

The server has 1 socket on a port.

(Let's talk about my webserver on port 80.)

It keeps doing TCPAccept on that port until it gets a connection

This socket recieved is a direct connection to 1 client.

You can close this socket without affecting the main socket.

#)

Posted

Thank you nfwu, I will look those TCP examples.

And I think I've understood better the tcpAccept thing.

In other words I need the mainSocket made by tcpListen and then I can have several ones with TcpAccept for every client and I can remove these sockets without loosing the main.

Ok, I must look at my telnet client code, now. I'll look at some clients examples to understand why it doesn't work well.

Posted

I have a look at some client examples and I found nothing different from what I wrote, in the essential parts.

I modified my script to work with a server in local 127.0.0.1 to see if/how it passes the strings and it works like expected.

So, now I don't know what it could be. Maybe a password coding/problem?

I would like to try to telnet to some different host without the need of a password, just to see something different to test.

What connection could I try?

I thought at a web connection, like:

#include <GUIConstants.au3>
TCPStartup()

$_IP = TCPNameToIP("www.google.it")

$port = "80"

Dim $ConnectedSocket = -1
$ConnectedSocket = TCPConnect($_IP , $port )

If $ConnectedSocket = -1 Then 
    MsgBox(16, "Error", "Unable to connect.") 
EndIf

;;;GUI
$GOOEY = GUICreate("Telnet client",700,400)
$edit = GUICtrlCreateEdit("",10,200,680,350,$WS_DISABLED)
$input = GUICtrlCreateInput("",10,10,400,180)
$butt = GUICtrlCreateButton("Send",420,10,80,20,$BS_DEFPUSHBUTTON)
GUISetState()

dim $text = "GET / HTTP/1.1" & @CR & "Host: www.google.it" & @CR & "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2" _
 & @CR & "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" _
 & @CR & "Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3" _
 & @CR & "Accept-Encoding: gzip,deflate" _
 & @CR & "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" _
 & @CR &"Keep-Alive: 300" _
 & @CR & "Connection: keep-alive" _

GUICtrlSetData($input,$text)

Dim $msg, $recv, $ret
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

;;; receive part
    $recv = TCPRecv( $ConnectedSocket, 2048)
    If @error Then ExitLoop
    If $recv <> "" Then       
           MsgBox(0, "Received Packet", $recv)   
           GUICtrlSetData($edit, " > " & $recv & @CRLF & GUICtrlRead($edit))
    EndIf

;;; send part
   If $msg = $butt Then
    $ret = TCPSend( $ConnectedSocket , GUICtrlRead($input))
    
    If @ERROR Or $ret < 0 Then 
        ExitLoop
    Else
        MsgBox(0, "Sent Packet", $ret)   
    EndIf

    GUICtrlSetData($input,"")
        GUICtrlSetState($input,$GUI_FOCUS)
   EndIf

WEnd


Func OnAutoItExit()
    If $ConnectedSocket <> - 1 Then
        TCPCloseSocket($ConnectedSocket)
    EndIf
    TCPShutdown()
EndFunc;==>OnAutoItExit

and then I could simulate a web browser answer, with:

GET / HTTP/1.1
Host: www.google.it
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

to see some response... but this does not work.

Maybe I must find a simpler connection... :D

HELP please.

Posted

I added:

If $recv <> "" Then MsgBox(0, "Received Packet", $recv)

to check the returning packets and I noticed that when I send my input string (the password), I receive two different answer, the first with 1* and the second with the rest of the chars:

I send this pass:

"test"

I get:

*

***

What does this mean?

Maybe I must send each char instead of the entire pass in one shot.

And maybe I must add the Enter code!

How can I pass the "Enter"?

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
  • Recently Browsing   0 members

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