frank10 Posted June 23, 2006 Posted June 23, 2006 (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? I made this attempt: expandcollapse popup#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 June 24, 2006 by frank10
frank10 Posted June 24, 2006 Author Posted June 24, 2006 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
nfwu Posted June 24, 2006 Posted June 24, 2006 http://www.autoitscript.com/forum/index.php?showtopic=20589TCP 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 connectionThis socket recieved is a direct connection to 1 client.You can close this socket without affecting the main socket.#) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode()
frank10 Posted June 24, 2006 Author Posted June 24, 2006 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.
frank10 Posted June 24, 2006 Author Posted June 24, 2006 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: expandcollapse popup#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... HELP please.
frank10 Posted June 24, 2006 Author Posted June 24, 2006 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"?
frank10 Posted June 26, 2006 Author Posted June 26, 2006 I solved my problem. I made a (silly) error.Look here for the script:http://www.autoitscript.com/forum/index.ph...id=199923&#
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now