Questions tagged [telnetlib]

The telnetlib module provides a Telnet class that implements the Telnet protocol under Python programming language.

The telnetlib module provides a Telnet class that implements the Telnet protocol under Python programming language.

See RFC 854 for details about the Telnet protocol.

In addition, telnetlib provides symbolic constants for the protocol characters (see below), and for the telnet options. The symbolic names of the telnet options follow the definitions in arpa/telnet.h, with the leading TELOPT_ removed. For symbolic names of options which are traditionally not included in arpa/telnet.h, see the module source itself.

Read more about telnetlib at python docs..

318 questions
4
votes
1 answer

python telnetlib expect error: TypeError: can't use a string pattern on a bytes-like object

I am trying to pass 2 precompiled regular expressions to python's telnetlib expect method, but I get: TypeError: can't use a string pattern on a bytes-like object. Sample code is below: import…
user1895318
  • 41
  • 1
  • 2
3
votes
2 answers

Python telnetlib3 examples

I would like to understand how to use telnetlib3 for a simple scenario. The longstanding telnetlib (not 3) has a simple example at https://docs.python.org/3/library/telnetlib.html where the python program connects to a telnet server, then looks for…
gwideman
  • 2,705
  • 1
  • 24
  • 43
3
votes
1 answer

Connection to a router does not open

I try to connect to a router R1 with GNS3 using a Python script: import getpass import sys import telnetlib HOST = "192.168.1.1" user = raw_input("Enter your remote account: ") password = getpass.getpass() tn =…
Nataila
  • 41
  • 6
3
votes
2 answers

Python3: Is there a way to use telnetlib like in python2, without ascii encode and b prefix?

Is there a way to make python2 scripts compatible with python3 with telnetlib? I noticed that I need to prefix read_until() with the letter b, and I need to use encode('ascii') on the string when I want to write(). Python2 tn =…
ForeverLearning
  • 413
  • 5
  • 25
3
votes
2 answers

How to give commands inside telnet session using python

I am writing python script to automate some task in simulator... to connect to simulator command is telnet localhost . This command I am giving through os.system(telnet localhost ). It is working. And simulator is running: Trying…
chitra
  • 79
  • 1
  • 7
3
votes
2 answers

Python telnetlib: surprising problem

I am using the Python module telnetlib to create a telnet session (with a chess server), and I'm having an issue I really can't wrap my brain around. The following code works perfectly: >>> f = login("my_server") #code for login(host) below. >>>…
ptz
  • 33
  • 1
  • 3
3
votes
1 answer

Python telnet client

Everyone, hello! I'm currently trying to use Telnetlib (https://docs.python.org/2/library/telnetlib.html) for Python 2.7 to communicate with some external devices. I have the basics set up: import sys import telnetlib tn_ip = xxxx tn_port =…
user5740843
  • 1,540
  • 5
  • 22
  • 42
3
votes
1 answer

Python telnetlib client doesn't appear to be opening telnet connection to server

I am trying to open a telnet connection, write one string, then print everything from the telnet server in Python. I assume I am missing something obvious because the documentation seems pretty self-explanatory and doing what I think is the exact…
zjuhasz
  • 1,489
  • 12
  • 30
3
votes
3 answers

telnetlib python read_all() not working(hangs)

I am trying to read from a cisco router using telnetlib import telnetlib tn = telnetlib.Telnet(’10.106.218.50’, 17280) cmd1=”enable” cmd2=”show run” #session.write("command".encode('ascii') + b"\r") tn.write(cmd1.encode('ascii') +…
fsociety
  • 977
  • 3
  • 12
  • 23
3
votes
2 answers

Can I clear the output buffer in Telnetlib on Python 2.7

I am using telnetlib to print the output after the last command i write to server tn.write(cmd_login) tn.write(cmd...) tn.write(cmd_last) print tn.expect([word],timeout)[-1] however, when I printed the return of expectation , it also show the…
newBike
  • 14,385
  • 29
  • 109
  • 192
3
votes
1 answer

How can I use a telnet command in Python to check for absence data flow on a remote server

I have a remote server with an IP address and a port. I can connect to it using a standard command window successfully. When using the command window, I can see data flow through the window but I lack the ability to be notified if the data flow…
Munkeyarms
  • 31
  • 2
3
votes
1 answer

Is it possible to send "resize pty" command with telnetlib?

I am looking for a way to resize terminal when using telnetlib. I have achieved a similar effect on SSH with Paramiko's resize_pty, but I need to support telnet protocol too. Is this even possible (does telnet even have a control stream)? Note that…
johndodo
  • 17,247
  • 15
  • 96
  • 113
2
votes
1 answer

Python Telnetlib and connecting timeout

I am trying to make a script, which connects to a server by telnet. I am using python and telnetlib. I have problems getting timeout to work. I want to use the optional timeout when connecting to host, so that I get an exception if the host isn't…
makarhum
  • 68
  • 1
  • 4
2
votes
1 answer

Python Telnet Port 23 vs 223 with Different Results

When I run this Python 3.1 code to access a device using telnetlib, it works as expected: import telnetlib tn = telnetlib.Telnet("15.39.100.126", "23") tn.write(b"menu\n") tn.write(b"0\n") print(tn.read_all().decode('ascii')) Then, I run this code…
Thom Ives
  • 3,642
  • 3
  • 30
  • 29
2
votes
2 answers

uploading file via telnet

Im writing a python scrpit to upload files to my file server: host = "myhost.dev" tn = telnetlib.Telnet() tn.open(host, 5202) print tn.read_until("\n") fp = "./output" f = open(fp, "r") f_body =…
JosiP
  • 2,619
  • 5
  • 29
  • 33
1
2
3
21 22