rudi Posted February 19, 2010 Share Posted February 19, 2010 (edited) Hi. I cannot work out what's the constraint here The general script layout is working fine for all our devices except the brocade fibrechannel switches: ; autoit 3.3.4.0 $IP = "10.28.33.8" $Port = 23 $foo = "" $trace = FileOpen("C:\temp\trace.txt", 2) TCPStartup() $Socket = TCPConnect($IP, $Port) $start = TimerInit() While 1 $read = TCPRecv($Socket, 100) If $foo <> $read Then ConsoleWrite($read) FileWrite($trace, $read) $foo = $read EndIf If StringInStr($read, "login:") Then ExitLoop EndIf Sleep(25) If TimerDiff($start) > 5000 Then ExitLoop WEnd FileClose($trace) TCPCloseSocket($Socket) TCPShutdown() ConsoleWrite(@CRLF & "done." & @CRLF) The Brocade give me just this through the script: ÿýÿý ÿý#ÿý' All other devices, e.g. Cisco 3570 give that one: --------- c:\temp\trace.txt ----------- ÿûÿûÿýÿý --- ALTBAU --- Cisco 3570 Stack. Giga-24-Port(Unten) = Master User Access Verification Password: ----------- EOF ----------- who knows, what I'm missing? Regards, Rudi. Edited February 19, 2010 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
rudi Posted February 19, 2010 Author Share Posted February 19, 2010 Hi. I had to recognize, that TELNET can be much, much more complicated than I expected due to my experience so far: These Brocade FC-Switches do a *LOT* of negotiation ( rubbish ) prior the main data exchange: Using wireshark I pulled out the HEX strings exchanged between a regular telnet session (MS TELNET.EXE) and the switch. This script is now working fine to get rid of the negotiation process: expandcollapse popup; autoit 3.3.4.0 #include <string.au3> $IP = "10.28.33.8" $Port = 23 $foo = "" $trace = FileOpen("C:\temp\trace.txt", 2) TCPStartup() $Socket = TCPConnect($IP, $Port) $start = TimerInit() Dim $NegArr[14][2] = [[13], _ ; Negotiation Array: Telnet is neg.ing terminal type, echo, other rubbish... [_Hex("fffd18fffd20fffd23fffd27"), _Hex("fffb18fffb1f")], _ [_Hex("fffd1f"), _Hex("fffb1ffffb20fffb18fffb27fffd01fffb03fffd03")], _ [_Hex("fffb01fffd03fffb03")], _ ; no SEND to that one [_Hex("fffd18fffd20fffd23fffd27"), _Hex("fffb18fffb1f")], _ [_Hex("fffd1f"), _Hex("fffc20fffc23fffb27")], _ [_Hex("fffa2701fff0fffa1801fff0"), _Hex("fffa1f0078003cfff0")], _ ["", _Hex("fffa2700fff0fffa1800414e5349fff0")], _ ; no RECV, just SEND [_Hex("fffb03fffd01fffb05fffd21"), _Hex("fffd03")], _ ["", _Hex("fffb01fffe05fffc21")], _ ; no RECV, just SEND [_Hex("fffe01fffb010d0a0d0a466162726963204f5320284243312d4643535731290d0a"), _Hex("fffc01")], _ ["", _Hex("fffd01")], _ ; no RECV, just SEND [_Hex("4661626f732056657273696f6e20362e322e30650d0a")], _ ; no SEND to that one [_Hex("0d0a0d0a4243312d4643535731206c6f67696e3a20"), _Hex("")]] Dim $Pointer = 1, $sum = "", $foo = "" While 1 Sleep(25) If TimerDiff($start) > 5000 Then ExitLoop $read = TCPRecv($Socket, 100) If $foo <> $read Then ConsoleWrite($foo) $foo = $read $sum &= $read EndIf If $NegArr[$Pointer][0] = "" Then ; don't wait, just send next reply TCPSend($Socket, $NegArr[$Pointer][1]) $Pointer += 1 Else $Len = StringLen($NegArr[$Pointer][0]) If StringRight($sum, $Len) = $NegArr[$Pointer][0] Then TCPSend($Socket, $NegArr[$Pointer][1]) $Pointer += 1 EndIf EndIf If $Pointer > $NegArr[0][0] Then ExitLoop WEnd ConsoleWrite(@CRLF & StringLen($sum) & " = länge" & @CRLF) FileClose($trace) TCPCloseSocket($Socket) TCPShutdown() ConsoleWrite(@CRLF & "done." & @CRLF) Func _Hex($foo) ConsoleWrite($foo & " = ") $foo = _HexToString($foo) ConsoleWrite($foo & @CRLF) Return ($foo) EndFunc ;==>_Hex Next will be to try the command dialog that I basically need. BTW: Is there really no freeware scriptable telnet client? That lines above were interesting to learn about telnet, but it's not comfortable at all... Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
enaiman Posted February 21, 2010 Share Posted February 21, 2010 Building "your own" telnet client looks like a big thing, but, telnet is much more complex than a simple TCP Send/Receive (you've experienced that). I think you should use the windows Telnet client (using StdInWrite and StdOutRead you can really use it in a nice way) or putty or any other freeware you can find. I haven't worked with putty yet but people say it's easy to work with. 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 :) Link to comment Share on other sites More sharing options...
Sn3akyP3t3 Posted February 24, 2010 Share Posted February 24, 2010 Rudi I recommend Putty as well for any scriptable Telnet, SSH, and Console needs especially with Cisco switches. I've tried other means of capturing logs or reading data from other client utilities, but none other than Putty have been practical. Putty allows for a logfile to be generated that is almost in real time with the running client to reflect what is on screen. The logfile can be parsed, although not directly, see my post on that if curious.Here is some code you can use to apply to your own project. I appreciate suggestions for improvements.expandcollapse popupFunc startPuttyTelnet() Run("C:\Program Files\PuTTY\putty.exe") WinWait("PuTTY Configuration") If Not WinActive("PuTTY Configuration") Then WinActivate("PuTTY Configuration") WinWaitActive("PuTTY Configuration") Send($sIpAddress) ;port 23 automatically selected Send("!t") ;select Telnet Send("+{TAB 3}") Sleep(250) Send("{DOWN}") ;enter logging options window ControlSend("PuTTY Configuration", "Log &file name:", "Edit1", "{DEL 10}") ;ControlSetText("PuTTY Configuration", "Log &file name:", "Edit1", $sPuttyLogFileLocation & "\Putty.log") ;disabled for workaround ControlSetText("PuTTY Configuration", "Log &file name:", "Edit1", $sTempPuttyFileLocation & "\Putty.log") If Not WinActive("PuTTY Configuration") Then WinActivate("PuTTY Configuration") WinWaitActive("PuTTY Configuration") ;select printable output Send("!p") If Not WinActive("PuTTY Configuration") Then WinActivate("PuTTY Configuration") WinWaitActive("PuTTY Configuration") ;select always overwrite existing log Send("!e{UP 3}") ;delete existing logfile to prevent handling leftover logfile from previous sessions masking problems If FileExists($sPuttyLogFileLocation & "\Putty.log") Then FileDelete($sPuttyLogFileLocation & "\Putty.log") FileDelete($sTempPuttyFileLocation & "\Putty.log") ;temporary workaround EndIf If Not WinActive("PuTTY Configuration") Then WinActivate("PuTTY Configuration") WinWaitActive("PuTTY Configuration") If Not WinActive("PuTTY Configuration") Then WinActivate("PuTTY Configuration") WinWaitActive("PuTTY Configuration") ControlClick("PuTTY Configuration", "&Open", "Button1") EndFunc Func startPuttySsh() Run("C:\Program Files\PuTTY\putty.exe") WinWait("PuTTY Configuration") If Not WinActive("PuTTY Configuration") Then WinActivate("PuTTY Configuration") WinWaitActive("PuTTY Configuration") Send($sIpAddress) ;port 22 automatically selected Send("!s") ;select SSh Send("+{TAB 3}") Sleep(250) Send("{DOWN}") ;enter logging options window ControlSend("PuTTY Configuration", "Log &file name:", "Edit1", "{DEL 10}") ;ControlSetText("PuTTY Configuration", "Log &file name:", "Edit1", $sPuttyLogFileLocation & "\Putty.log") ;disabled for workaround ControlSetText("PuTTY Configuration", "Log &file name:", "Edit1", $sTempPuttyFileLocation & "\Putty.log") If Not WinActive("PuTTY Configuration") Then WinActivate("PuTTY Configuration") WinWaitActive("PuTTY Configuration") ;select printable output Send("!p") If Not WinActive("PuTTY Configuration") Then WinActivate("PuTTY Configuration") WinWaitActive("PuTTY Configuration") ;select always overwrite existing log Send("!e{UP 3}") ;delete existing logfile to prevent handling leftover logfile from previous sessions masking problems If FileExists($sPuttyLogFileLocation & "\Putty.log") Then FileDelete($sPuttyLogFileLocation & "\Putty.log") FileDelete($sTempPuttyFileLocation & "\Putty.log") ;temporary workaround EndIf If Not WinActive("PuTTY Configuration") Then WinActivate("PuTTY Configuration") WinWaitActive("PuTTY Configuration") ControlClick("PuTTY Configuration", "&Open", "Button1") If WinWait("PuTTY Security Alert", "The server's host key is not cached", 5) Then If Not WinActive("PuTTY Security Alert") Then WinActivate("PuTTY Security Alert") WinWaitActive("PuTTY Security Alert") ControlClick("PuTTY Security Alert", "&Yes", "Button1") EndIf EndFuncFor the full project download see here. Link to comment Share on other sites More sharing options...
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