Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
telnet question
#1
Hi All,
i have some question related to telnet this script. Are we able to login and don't close the session. For example login, and user is able to type in command like that. I saw most of the resource on net, only show login and run some command. Is it possible to just login automatic and stop.
For my script, it will login and run the command. But what i wants is just login, and don't exit the session.

Is python able to do this?

Name: telnet_demo.py

Tesed in python3.5
"""
import telnetlib

HOST = "192.168.1.253"
user = "root"
password = "arrisc4"


def command(con, flag, str_=""):
    data = con.read_until(flag.encode())
    print(data.decode(errors='ignore'))
    con.write(str_.encode() + b"\n")
    return data

tn = telnetlib.Telnet(HOST)
command(tn, "Login:", user)
if password:
    command(tn, "Password:", password)
command(tn, "#", "en")
#command(tn, "$", " exit")
#command(tn, "$", "")
tn.close()
Reply


Messages In This Thread
telnet question - by jacklee26 - Mar-23-2019, 12:04 PM
RE: telnet question - by nilamo - Mar-29-2019, 05:45 PM
RE: telnet question - by jacklee26 - Mar-30-2019, 06:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  telnet from ssh tunnel oldfart 3 7,331 Jul-17-2020, 02:28 PM
Last Post: noobami99
  telnet to a device under tacacs management kang18 0 1,639 Jun-05-2020, 06:11 AM
Last Post: kang18
  3.6 telnet eyler 3 11,411 Jun-28-2019, 05:22 AM
Last Post: Khanhamid90
  Any suggestion on python library to use for both ssh and telnet? lord_mani 4 3,885 Jun-25-2019, 04:07 PM
Last Post: gb74razor
  Retrieve output from telnet command Networker 1 4,209 Mar-12-2019, 01:36 PM
Last Post: searching1
  Aggregate multiple telnet connections Jibeji 1 4,347 Mar-02-2018, 07:21 PM
Last Post: mpd
  Multithread telnet not working Parallel anna 7 7,649 Feb-05-2018, 01:17 PM
Last Post: anna
  Python telnet script for IP list mangesh 1 68,952 Jun-26-2017, 11:12 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020