Hi all,
I have my first need to play with the telnetlib module, and am having some
good successes, but some puzzling failures. I'm hoping that someone here can
shed some light on what's happening.
First the trace from my telnet session:
Telnet(host.abcde.com,23): recv '\015\012SFW 123.123.123.123\015\012'
Telnet(host.abcde.com,23): recv '\024\005'
Telnet(host.abcde.com,23): send 'ABCDEFGH'
Telnet(host.abcde.com,23): recv 'Welcome to Stellar 3\015\012ABCDEFGHI
\015\012'
Telnet(host.abcde.com,23): recv '\015\000\015\000Enter Public ID: '
Telnet(host.abcde.com,23): send 'XYZ\012'
Telnet(host.abcde.com,23): recv 'X'
Telnet(host.abcde.com,23): recv 'YZ\015\012'
Telnet(host.abcde.com,23): recv '\015\000\015\000Enter Private ID: '
Telnet(host.abcde.com,23): send '1234567\012'
Telnet(host.abcde.com,23): recv '*'
Telnet(host.abcde.com,23): recv '*'
Telnet(host.abcde.com,23): recv '*****\010 \010\010 \010\010 \010\010
\010\010 \010\010 \010\010 \010\015\012'
Telnet(host.abcde.com,23): recv '\015\012'
Telnet(host.abcde.com,23): recv 'You have Personal and General mail.\015\012'
Telnet(host.abcde.com,23): recv '\015\012Enter Terminal Type ( PIC default -
? for valid '
Telnet(host.abcde.com,23): recv 'types): '
Telnet(host.abcde.com,23): send 'XTERM\012'
Telnet(host.abcde.com,23): recv 'X'
Telnet(host.abcde.com,23): recv 'T'
Telnet(host.abcde.com,23): recv 'ERM'
Now the code:
host = telnetlib.Telnet(hostname)
host.set_debuglevel(255)
host.read_until('\024\005')
host.write(answerback)
host.read_until('Public ID: ')
host.write(username + '\n')
host.read_until('Private ID: ')
host.write(password + '\n')
host.read_until('): ') #Set the terminal Type
host.write('XTERM\n')
#My code stops function at this point
#The following prompt never appears
host.read_until('): ') #Set the terminal Rows
host.write('24\n')
Now the problem.
Everything works great until I enter the Terminal type. It appears that the
telnet session stops receiving at that point. As you can see from the
Traceback I receive the echo of from my write, but then don't receive the
next prompt.
I'm guessing it has something to do with either changing the terminal type
on telnetlib, or a timing issue, but I'm stumped at the moment.
One other point, even if I go with the default terminal type, I have the
same problem.
Any suggestions will be greatfully accepted.
Thanks.
--
Stand Fast,
tjg.
Timothy Grant tjg(a)exceptionalminds.com
Chief Technology Officer www.exceptionalminds.com
Red Hat Certified Engineer (503) 246-3630
Avalon Technology Group, Inc. fax (503) 246-3124
>>>>>>>>>>>>Linux...Because crashing isn't normal<<<<<<<<<<<<<
>say I had a string.
>this_string = "jesse(a)multimediacollective.com"
>"""and I wanted to get rid of the @, how would I do that? This
>process has to be efficent for removing large quantities of special
>characters, such as <,>,#,%,* etc, from the same string.
>Any advice would be very helpful. Thanks in advance, Jesse.
You could do this, not sure how fast or slow it is.
>>>
>>> import re
>>> this_string = "jesse(a)multimediacollective.com"
>>> pattern = re.compile('\W')
>>> new_line = re.sub(pattern, '', this_string)
>>> new_line
'jessemultimediacollectivecom'
>>>
It will remove all non alphanumeric characters from a string.
For more info on re have a look at the Regular Expression HOWTO
http://www.python.org/doc/howto/regex/regex.html
john
johnh(a)phm.gov.au