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
1
vote
1 answer

Catch sshtunnel exception with Python

I have a python code that brings up an SSH connection to remote server to further forward telnet traffic to several routers hidden behind this server, in order to remote manage those. The code is the following: def sshStart(self): try: …
Lucas Aimaretto
  • 1,399
  • 1
  • 22
  • 34
1
vote
0 answers

Python telnetlib: multiple clients simultaniously

I have an IoT project which utilizes two ESP8266 which serve as UART bridges over wifi and I'm trying to make them communicate with a Raspberry pi using Python. And since the protocol used by these chips is telnet, I tried using the telnetlib…
R3D34THR4Y
  • 51
  • 6
1
vote
0 answers

Read telnet python output and ignore ansi escape code

I'm trying to do a putty-like in python for personnal solution but i can't read the resultat properly. I receive all ansi code from the switch b'HEWLETT-PACKARD COMPANY, 3000 Hanover St., Palo Alto, CA…
Pierro
  • 11
  • 3
1
vote
1 answer

Python telnetlib.expect() dot character '.' not working as expected

I am trying to automate generic telnet connections. I am relying heavily on REGEX to handle different login prompts. Currently, I am using the regex [Ll]ogin, but the prompt causing me problems is the standard Ubuntu prompt: b-davis login:…
Rudedog9d
  • 61
  • 3
  • 10
1
vote
1 answer

telnetlib .read_until second match

I'm new to python or any language but I'm trying to write this script to facilitate some tasks, I'm having this issue with the python telnetlib, that I'm trying to read the output of the ssh session with .read_until(comm_prompt) but it always seems…
Victor
  • 11
  • 2
1
vote
2 answers

Python telnet connection successful

I'm wondering if it is possible to know if my telnet connection is successful? So, if I'm connected to my switch and if I could write commands telnet = telnetlib.Telnet(IP) telnet.read_until(b"User…
Eduloc
  • 53
  • 2
  • 2
  • 9
1
vote
1 answer

Telnetlib's read_until in Python will not read expected string. What are Alternatives?

import getpass import sys import telnetlib host = "10.28.103.126" user = b"apc" password = b"apc" outlet = b"8" tnObject = telnetlib.Telnet(host) print("yes") tnObject.read_until(b"User Name :") tnObject.write(user + b"\n") print("sent…
1
vote
1 answer

Ignore special characters when creating a regular expression in python

Is there a way to ignore special character meaning when creating a regular expression in python? In other words, take the string "as is". I am writing code that uses internally the expect method from a Telnet object, which only accepts regular…
Sci Prog
  • 2,651
  • 1
  • 10
  • 18
1
vote
3 answers

Python - telnet on routers and list full result (hitting space bar)

import telnetlib def telNetCall(): host = "10.200.1.23" user = "me" password = "matrix" telnet = telnetlib.Telnet(host) telnet.read_until('Username: ', 3) telnet.write(user + '\r') telnet.read_until('Password: ', 3)…
Whit3H0rse
  • 569
  • 2
  • 8
  • 16
1
vote
1 answer

Python telnetlib read_all hangs until timeout

I have some Python code that connects via telnet to an OSPF daemon (ran by Quagga) and then does the following: tn.write("show ip ospf database router\n") tn.write("exit\n") my_text = tn.read_all() When the output of show ip ospf database router…
1
vote
1 answer

Restrict or limit read_very_eager() in python

I am executing a few commands on a remote machine which runs linux over a telnet session using telnet lib. When I give the following : tn.write("") time.sleep(10) tn.write("cat…
skrowten_hermit
  • 437
  • 3
  • 11
  • 28
1
vote
1 answer

Python telnetlib ending session

If I am using Python telnetlib, is there a way to close the telnet session if that device does not support nothing to terminate telnet session, so no ctrl+something or quit or anything like that. I need this so that I could use read.all
Dominik
  • 311
  • 1
  • 4
  • 11
1
vote
0 answers

Python to telnet localhost using an SSH connection

I'd like to automate some tests performed in this way: 1)SSH Connection to a remote host usinn PuTTY 2)Telnet connection from this remote host to itself localhost 3)Command sending using telnet connection I'd like to automate the command…
Vigmarco
  • 11
  • 1
1
vote
1 answer

print tn.read_all() does not return anything in telnetlib python script

I am trying to telnet into a cisco ios-xr router and gather command output. I have tested that the below code successfully connects to the router and executes the command, however it seems that neither print tn.read_all() nor tn.read_very_eager()…
OzgurGuler
  • 11
  • 1
  • 3
1
vote
1 answer

How to read only last buffer from telnetlib command

I have following python code: import telnetlib ts = telnetlib.Telnet('192.168.0.2') ts.set_debuglevel(10) ts.read_until("assword:", 5) ts.write("xxxxx\n") ts.write("enable\n") ts.read_until("assword:", 5) ts.write("xxxxx\n") ts.write("term len…
kamoks
  • 85
  • 2
  • 7