I was trying to create a control script for an HP procurve switch. The chararcters being returned from the python telnet read_until command appear to contain a variety of unexpected characters. See example below. When accessing the same device using the default redhat telnet client the characters do not appear to be returned. Are there options on the python telnet open command to alleviate this issue?

Sample string returned from python read_until command:

[root@esp-pm-01 ~]# python
Python 2.4.3 (#1, Mar 14 2007, 18:51:08)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import telnetlib
>>> f = telnetlib.Telnet()
>>> f.open('15.29.18.93', '2001')
>>> f.write('show flash\n')
>>> f.read_until('> ',2)
'\x1b[24;27Hs\x1b[24;27H\x1b[?25h\x1b[24;28H\x1b[24;28Hh\x1b[24;28H\x1b[?25h\x1b[24;29H\x1b[24;29Ho\x1b[24;29H\x1b[?25h\x1b[24;30H\x1b[24;30Hw\x1b[24;30H\x1b[?25h\x1b[24;31H\x1b[24;31H \x1b[24;31H\x1b[?25h\x1b[24;32H\x1b[24;32Hf\x1b[24;32H\x1b[?25h\x1b[24;33H\x1b[24;33Hl\x1b[24;33H\x1b[?25h\x1b[24;34H\x1b[24;34Ha\x1b[24;34H\x1b[?25h\x1b[24;35H\x1b[24;35Hs\x1b[24;35H\x1b[?25h\x1b[24;36H\x1b[24;36Hh\x1b[24;36H\x1b[?25h\x1b[24;37H\x1b[24;0H\x1bE\x1b[24;1H\x1b[24;37H\x1b[24;1H\x1b[2K\x1b[24;1H\x1b[?25h\x1b[24;1H\x1b[1;24r\x1b[24;1HImage Size(Bytes) Date Version\r\n----- ---------- -------- -------\r\nPrimary Image : 6126444 05/25/07 T.12.09 \r\nSecondary Image : 6126444 05/25/07 T.12.09 \r\nBoot Rom Version: K.11.03\r\nCurrent Boot : Primary\r\n\r\n\x1b[1;24r\x1b[24;1H\x1b[24;1H\x1b[2K\x1b[24;1H\x1b[?25h\x1b[24;1H\x1b[24;1HProCurve Switch 2900-48G> '
>>>

Expected the string to contain something like the following as returned by the default telnet client in redhat linux:

[root@esp-pm-01 ~]# telnet 15.29.18.93 2001
Trying 15.29.18.93...
Connected to 15.29.18.93
Escape character is '^]'.

ProCurve Switch 2900-48G> show flash

Image Size(Bytes) Date Version
----- ---------- -------- -------
Primary Image : 6126444 05/25/07 T.12.09
Secondary Image : 6126444 05/25/07 T.12.09
Boot Rom Version: K.11.03
Current Boot : Primary

ProCurve Switch 2900-48G>
telnet> Connection closed.
[root@esp-pm-01 ~]#

Might be binary your looking at. Or encrypted stuff but Telnet is not known for standard encryptions.
Good Luck.

try

>>> print '\x1b[24;27Hs\x1b[24;27H\x1b[?25h\x1b[24;28H\x1b[24;28Hh\x1b[24;28H\x1b[?25h\x1b[24;29H\x1b[24;29Ho\x1b[24;29H\x1b[?25h\x1b[24;30H\x1b[24;30Hw\x1b[24;30H\x1b[?25h\x1b[24;31H\x1b[24;31H \x1b[24;31H\x1b[?25h\x1b[24;32H\x1b[24;32Hf\x1b[24;32H\x1b[?25h\x1b[24;33H\x1b[24;33Hl\x1b[24;33H\x1b[?25h\x1b[24;34H\x1b[24;34Ha\x1b[24;34H\x1b[?25h\x1b[24;35H\x1b[24;35Hs\x1b[24;35H\x1b[?25h\x1b[24;36H\x1b[24;36Hh\x1b[24;36H\x1b[?25h\x1b[24;37H\x1b[24;0H\x1bE\x1b[24;1H\x1b[24;37H\x1b[24;1H\x1b[2K\x1b[24;1H\x1b[?25h\x1b[24;1H\x1b[1;24r\x1b[24;1HImage Size(Bytes) Date Version\r\n----- ---------- -------- -------\r\nPrimary Image : 6126444 05/25/07 T.12.09 \r\nSecondary Image : 6126444 05/25/07 T.12.09 \r\nBoot Rom Version: K.11.03\r\nCurrent Boot : Primary\r\n\r\n\x1b[1;24r\x1b[24;1H\x1b[24;1H\x1b[2K\x1b[24;1H\x1b[?25h\x1b[24;1H\x1b[24;1HProCurve Switch 2900-48G> '

On my linux console, it works. I think the special characters are instructions for the terminal. It could be curses characters. The output here is

show flash
Image Size(Bytes) Date Version
----- ---------- -------- -------
Primary Image : 6126444 05/25/07 T.12.09
Secondary Image : 6126444 05/25/07 T.12.09
Boot Rom Version: K.11.03
Current Boot : Primary

ProCurve Switch 2900-48G>
>>>
This article has been dead for over six months. Start a new discussion instead.