tom13 Posted May 6, 2007 Posted May 6, 2007 Hi, I'm trying to figure out how to work with the TCP functions of AutoIT, so I'm connecting to my localhost (10.0.0.189) on port 3200. This works fine but I need to autenticate with password xxxxx (censored). I couldn't find a script to authenticate, so can anyone help me out? I need to know how to tell the server my password This is the script I use, copied from AutoIT help file. Thanks in advance. expandcollapse popup;CLIENT! Start Me after starting the SERVER!!!!!!!!!!!!!!! ; see TCPRecv example #include <GUIConstants.au3> ; Start The TCP Services ;============================================== TCPStartUp() ; Set Some reusable info ;-------------------------- Dim $szServerPC = @ComputerName ; Set $szIPADDRESS to wherever the SERVER is. We will change a PC name into an IP Address Dim $szIPADDRESS = "10.0.0.189" Dim $nPORT = "3200" ; Initialize a variable to represent a connection ;============================================== Dim $ConnectedSocket = -1 ;Attempt to connect to SERVER at its IP and PORT 33891 ;======================================================= $ConnectedSocket = TCPConnect($szIPADDRESS,$nPORT) Dim $szData ; If there is an error... show it If @error Then MsgBox(4112,"Error","TCPConnect failed with WSA error: " & @error) ; If there is no error loop an inputbox for data ; to send to the SERVER. Else ;Loop forever asking for data to send to the SERVER While 1 ; InputBox for data to transmit $szData = InputBox("Data for Server",@LF & @LF & "Enter data to transmit to the SERVER:") ; If they cancel the InputBox or leave it blank we exit our forever loop If @error Or $szData = "" Then ExitLoop ; We should have data in $szData... lets attempt to send it through our connected socket. TCPSend($ConnectedSocket,$szData) ; If the send failed with @error then the socket has disconnected ;---------------------------------------------------------------- If @error Then ExitLoop WEnd EndIf
erebus Posted May 6, 2007 Posted May 6, 2007 Hi,I haven't checked this out, but have a look here: http://www.autoitscript.com/forum/index.php?showtopic=28088I hope it helps,
tom13 Posted May 6, 2007 Author Posted May 6, 2007 Hi,I haven't checked this out, but have a look here: http://www.autoitscript.com/forum/index.php?showtopic=28088I hope it helps,Thanks for your help, I still can't figure out how to authenticate though, with the examples I made it so it would send my password when it connects but this has no effect When I do it in telnet I connect and then type my password + press enter and I get "Authentication OK"
enaiman Posted May 6, 2007 Posted May 6, 2007 (edited) I do alot of work with switches and the authentication process never been a problem to me.I use Tera Term (this is the download link) and it works great.However, in order to get it working you will need to use the "log" feature and to read the switch's answers from the text file.In order to send commands to switch - I use ControlSend and it works (be aware that ControlSend doesn't work on 3.2.2.0 - you can use 3.2.1.0 or the latest beta)The authentication process looks like:- Start TeraTerm in "log" mode (like telneting into the switch)- send an empty string (ENTER) to create a first line in the log- read the last line of the log (this is the switch prompt)- if the last line is "login" then send the username and ENTER- read again the last line which should contain "password"- if the content is "password" - send the password and ENTER- wait a little bit for login to be completed- read the last line of the log where you should find a prompt (like > or # or something else) if the login is succesful or "login failed" if it fails- if you got the prompt - congrats, you're in....-and so on ... you can send any commands and read the answers from the log.*if you would like to use TeraTerm be sure that the option "Append" is not checked - if it is then the log will grow very fast and it would be difficult to work with.You can always use the "log" ability of Windows Telnet also - the key is to get somehow the answers the switch is sending you. Edited May 6, 2007 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :)
tom13 Posted May 7, 2007 Author Posted May 7, 2007 I do alot of work with switches and the authentication process never been a problem to me.I use Tera Term (this is the download link) and it works great.However, in order to get it working you will need to use the "log" feature and to read the switch's answers from the text file.In order to send commands to switch - I use ControlSend and it works (be aware that ControlSend doesn't work on 3.2.2.0 - you can use 3.2.1.0 or the latest beta)The authentication process looks like:- Start TeraTerm in "log" mode (like telneting into the switch)- send an empty string (ENTER) to create a first line in the log- read the last line of the log (this is the switch prompt)- if the last line is "login" then send the username and ENTER- read again the last line which should contain "password"- if the content is "password" - send the password and ENTER- wait a little bit for login to be completed- read the last line of the log where you should find a prompt (like > or # or something else) if the login is succesful or "login failed" if it fails- if you got the prompt - congrats, you're in....-and so on ... you can send any commands and read the answers from the log.*if you would like to use TeraTerm be sure that the option "Append" is not checked - if it is then the log will grow very fast and it would be difficult to work with.You can always use the "log" ability of Windows Telnet also - the key is to get somehow the answers the switch is sending you.Hmm, thats nice but I want to make a 100% standalone program - with your solution all my users need to download tera term right?
enaiman Posted May 7, 2007 Posted May 7, 2007 (edited) Hmm, thats nice but I want to make a 100% standalone program - with your solution all my users need to download tera term right? Right. (or you can include the TeraTerm install within your script - Tera Term is freeware) As I've said before - you can use instead the Windows Telnet (you can start it in "log" mode); actually it doesn't matter which Telnet client you're using as long as you can get the switch answers from somewhere. EDIT: To give you a start I will post a simple code to do that you want - however, I will leave the part about detecting switch answers and such to you. Here is the code: Dim $delay = 0, $ip = "your IP here", $passwd = "your password here" $delay = Ping($ip) + Ping($ip) + Ping($ip) ;this delay is to be sure that it is enough time to get the prompt back from the switch Run("telnet "&$ip) Sleep(100 + $delay) ControlSend("Telnet", "", "","admin"&@CR) Sleep(100 + $delay) ControlSend("Telnet", "", "",$passwd&@CR) Edited May 8, 2007 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :)
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