473,503 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A python telnet entry level question

Hello Everyone,

I am trying to write a python script to telnet to a server and then do
something there. As the first step, I practiced the python example in Lib
Reference 11.13.2. But I am finding the script stops after I supplied the
password. Does anyone know why?
Thanks in advance!

Jinming Xu

PS: Here is the script:

import getpass
import sys
import telnetlib

HOST = "localhost"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")

tn.write("ls\n")
tn.write("exit\n")

print tn.read_all()

__________________________________________________ _______________
MSN Toolbar provides one-click access to Hotmail from any Web page – FREE
download! http://toolbar.msn.com/go/onm00200413ave/direct/01/
Jul 18 '05 #1
6 2738
It might be getting stuck on the Password part.

Try this:

tn.read_until("Password: ", 1)
Ethereal can be very helpful. Use it to see what is happening on the
wire. It has a "follow TCP stream" function. Obviously this will not
work for telneting to localhost so you will need to telnet to a remote host.

Good luck.
Andy

Jinming Xu wrote:
Hello Everyone,

I am trying to write a python script to telnet to a server and then do
something there. As the first step, I practiced the python example in
Lib Reference 11.13.2. But I am finding the script stops after I
supplied the password. Does anyone know why?
Thanks in advance!

Jinming Xu

PS: Here is the script:

import getpass
import sys
import telnetlib

HOST = "localhost"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")

tn.write("ls\n")
tn.write("exit\n")

print tn.read_all()

__________________________________________________ _______________
MSN Toolbar provides one-click access to Hotmail from any Web page –
FREE download! http://toolbar.msn.com/go/onm00200413ave/direct/01/


Jul 18 '05 #2
"Jinming Xu" <cy********@hotmail.com> writes:
Hello Everyone, I am trying to write a python script to telnet to a server and then do
something there. As the first step, I practiced the python example in Lib
Reference 11.13.2. But I am finding the script stops after I supplied the
password. Does anyone know why?
Thanks in advance! Jinming Xu PS: Here is the script: import getpass
import sys
import telnetlib HOST = "localhost"
user = raw_input("Enter your remote account: ")
password = getpass.getpass() tn = telnetlib.Telnet(HOST) tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n") tn.write("ls\n")
tn.write("exit\n") print tn.read_all()


You are maybe being too specific in what you match for. At least one of my
machines prompts:

Pasword for <username>:

rather than just "Password: ". I tend to match things like

"ogin" (in case of Login vs login)
"assword" (will this get filtered out by censoring s/w?)

Eddie
Jul 18 '05 #3
In article <c6**********@scotsman.ed.ac.uk>,
Eddie Corns <ed***@holyrood.ed.ac.uk> wrote:
Jul 18 '05 #4
cl****@lairds.com (Cameron Laird) writes:
In article <c6**********@scotsman.ed.ac.uk>,
Eddie Corns <ed***@holyrood.ed.ac.uk> wrote:
.
.
.
You are maybe being too specific in what you match for. At least one of my
machines prompts:

Pasword for <username>:

rather than just "Password: ". I tend to match things like

"ogin" (in case of Login vs login)
"assword" (will this get filtered out by censoring s/w?)

Eddie
This sort of tolerance can lead to its own problems (though
I entirely agree you're right to recommend it). Some logins
are so sensitive to timing (in essence) that matching
"assword" rather than "assword:" results in the telnetd
ignoring the first character or two of response. So what to do? At this level, there is *no* good answer.
The most enlightened thought is simply to recognize that
telnet forces one into a cascade of heuristic hacks.


And then you get unhelpful router manufacturers that put code in to check
whether passwords are typed too fast (or regularly spaced) and ignore them
because they're obviously not dealing with a human! Took me ages to figure
out why my scripts were failing (then about 10 seconds to defeat it).

Yes, using telnet is more art than science but it's a lot better now than
before we had expect (for heavy duty jobs) and telnetlib (for simpler jobs).

Eddie
Jul 18 '05 #5
In article <c6**********@scotsman.ed.ac.uk>,
Eddie Corns <ed***@holyrood.ed.ac.uk> wrote:
Jul 18 '05 #6
"Andrew Jones" <aj****@sgi.com> wrote in message
news:c6************@fido.engr.sgi.com...
It might be getting stuck on the Password part.

Try this:

tn.read_until("Password: ", 1)
Ethereal can be very helpful. Use it to see what is happening on the
wire. It has a "follow TCP stream" function. Obviously this will not
work for telneting to localhost so you will need to telnet to a remote host.

I just discovered telnetlib yesterday and found "set_debuglevel" to be very
useful to figure out what to read_until.

-Mark

Good luck.
Andy

Jinming Xu wrote:
Hello Everyone,

I am trying to write a python script to telnet to a server and then do
something there. As the first step, I practiced the python example in
Lib Reference 11.13.2. But I am finding the script stops after I
supplied the password. Does anyone know why?
Thanks in advance!

Jinming Xu

PS: Here is the script:

import getpass
import sys
import telnetlib

HOST = "localhost"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")

tn.write("ls\n")
tn.write("exit\n")

print tn.read_all()

__________________________________________________ _______________
MSN Toolbar provides one-click access to Hotmail from any Web page –
FREE download! http://toolbar.msn.com/go/onm00200413ave/direct/01/

Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1485
by: asdf sdf | last post by:
wondering what python resources might be available for python-based legacy system access, particularly to MVS, DB2 and Adabas. What additional pieces might be needed to implement this access? ...
4
11126
by: Donnal Walter | last post by:
On Windows XP I am able to connect to a remote telnet server from the command prompt using: telnet nnn.nnn.nnn.nnn 23 where nnn.nnn.nnn.nnn is the IP address of the host. But using telnetlib,...
23
2511
by: anton.vredegoor | last post by:
Here's my situation: I'm typing this in a public library on a computer with OS windows 2000 server. I can run Internet explorer, word, excel and powerpoint, that's it. Maybe java, but it seems...
4
5184
by: praba kar | last post by:
Dear All, Normally we can send mail using telnet in linux. In the following way telnet Ipaddress 25 mail from: raj@rajkumar.com 250 o.k(response of from commandline) rcpt to: test@oops.co.in...
5
5837
by: richardtinkler | last post by:
I need to communicate with a POP3 server using ASP. Does anybody have any ideas how I can set up a telnet connection using an ASP script? There are some components out there, but my host won't...
20
6880
by: hippomedon | last post by:
Hello everyone, I'm looking for some advice on whether I should break the normalization rule. Normally, I would not consider it, but this seems to be a special case. I have created an...
0
1965
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 385 open (+21) / 3790 closed (+21) / 4175 total (+42) Bugs : 1029 open (+43) / 6744 closed (+43) / 7773 total (+86) RFE : 262 open...
22
1845
by: pbd22 | last post by:
Hi. I am building a custom telnet interface and my problem is that I want to read the user input along with the previously written stream. Right now I am logging the user. I have Login:...
4
7249
by: SPJ | last post by:
Is it possible to run specific commands on cisco router using Python? I have to run command "show access-list" on few hundred cisco routers and get the dump into a file. Please let me know if it is...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5594
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4688
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.