[Tutor] Fwd: Re: I've subscribed to your service, no confirmation yet. I'm looking for a tutor and I need help with some code.
Alan Gauld
alan.gauld at yahoo.co.uk
Tue May 24 20:08:29 EDT 2016
Forwarding to the list.
Please use reply-all to respond to list messages.
Also please use plain text as HTML messages often result in
code listings being corrupted, especially the spacing, which
is very important in Python.
-------- Forwarded Message --------
> I just opened the python IDLE 3.5 on my MAC and I imported telnet.lib.
> On the next line I typed telnet 192.09.168.55 and I got an error. It said
> invalid syntax. I'm trying to telnet to my other MAC here at home, just
> to see if I can connect.
You cannot just type telnet commands into Python you need to use
the telnet API. (Type help(telnetlib) at the >>> prompt or visit the
modules documentation page)
A typical session might look something like:
>>> import telnetlib
>>> tn = telnetlib.Telnet('myhost.com')
>>> response = tn.read()
>>> print(response)
..... some stuff here ....
>>> tn.close()
That's assuming you have telnet access to myhost.com of course, many sites
don't allow it because of the security issues associated with telnet.
ssh is
probably a better bet.
But in either case don't expect a telnet interactive session - that's
what the
telnet command (or ssh) is for. Python gives you the ability to automate a
session, with no human interactivity required. If you want to interact
you'll
need to read the output and check for prompts from the host then relay
those prompts to your user from Python.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list