INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Python Telnet Client

Python Telnet Client

(OP)
Does anyone know of Python Telnet script that is already available that will allow you to telnet to a machine and input commands?

So I am guessing bidirectional client?

I want to see how it is done for a programming project I am thinking of.

RE: Python Telnet Client

(OP)
I have been able to make little progress. I can now make a connection, but I want to be able to read what is being transmitted to the client and display it on the python screen. Of course send input responses via the python script as well.

any clue how to do this? I would like it to be able to interpret not only ASCII but ANSI and IBM graphics if possible.

CODE --> Python

import os
import telnetlib

os.system("cls")
HOST = input("Enter Hostname: ")
PORT = input ("Port #: ")
tn = telnetlib.Telnet(HOST,PORT)

tn.read_all() 

RE: Python Telnet Client


An example using telnetlib

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind these jesus character, stars had to die for me to live.

RE: Python Telnet Client

(OP)
i have come across this one and even though it shows how to make the connection, it shows to read the lines until it meets a certain criteria.

What I want to do is read the whole line and/or the EOF and display it as well as accept input if needed.

So..

If I connect and the first line is "Connected to XYZ" or whatever it is. I want to display that line as it comes in. Then go to the next line and start over. If there is no carriage return then it should be set to take input from the client.

What i really want to do is code a python based telnet client if possible so it will only want input when input is really required.

Make sense?

RE: Python Telnet Client


I want to display that line as it comes in. Then go to the next line and start over

Use one of the .read_* objects to get the message(s), Then use sys.stdout.write to 'print' the messages 'in-line' (concatenated)

CODE --> Python

sys.stdout.write(message)
sys.stdout.flush() 

OR

CODE --> python

print(message) 
To output each one on a separate line.

then loop around the read->print construct until the .read_* raises a EOFError

Or if you use read_until() stop when the required match is reached.


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind these jesus character, stars had to die for me to live.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close