Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3.6 telnet
#1
Anyone have a function script using 3.6 for telnet? The script below doesn't accomplish anything.RUnning a debug on the switch I see a telnet attempt but I don't see a login for the user and none of the commands run.

import getpass
import sys
import telnetlib

HOST = "X.X.X.X" # I use the actual IP here.
user = input("Enter your Username: ")
password = getpass.getpass()
print("passed the getpass step")

tn = telnetlib.Telnet(HOST)


tn.read_until(b"Username: ")
tn.write(user.encode('ascii') + b"\n")
#tn.write(b"user" + "\n")
if password:
    tn.read_until(b"Password: ")
    tn.write(password.encode('ascii') + b"\n")

# not needed due login privilege 15 to tn.write("enable\n")
tn.write(b"config t" + "\n".encode('ascii'))
print("config t complete")
tn.write(b"interface loopback 0" + "\n".encode('ascii'))
print("interface loopback 0")
tn.write(b"ip address 1.1.1.1 255.255.255.255" + "\n".encode('ascii'))
print("IP address complete")
tn.write(b"end" + "\n".encode('ascii'))
tn.write(b"exit" + "\n".encode('ascii'))

print(tn.read_all().decode('ascii'))
input("\n\nPress the enter key to exit.")
Reply


Messages In This Thread
3.6 telnet - by eyler - Jan-29-2018, 09:09 PM
RE: 3.6 telnet - by snagwekar - May-04-2018, 10:27 PM
RE: 3.6 telnet - by pallavi - Jul-25-2018, 03:09 PM
RE: 3.6 telnet - by Khanhamid90 - Jun-28-2019, 05:22 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  telnet from ssh tunnel oldfart 3 7,168 Jul-17-2020, 02:28 PM
Last Post: noobami99
  telnet to a device under tacacs management kang18 0 1,569 Jun-05-2020, 06:11 AM
Last Post: kang18
  Any suggestion on python library to use for both ssh and telnet? lord_mani 4 3,749 Jun-25-2019, 04:07 PM
Last Post: gb74razor
  telnet question jacklee26 2 2,497 Mar-30-2019, 06:45 AM
Last Post: jacklee26
  Retrieve output from telnet command Networker 1 4,111 Mar-12-2019, 01:36 PM
Last Post: searching1
  Aggregate multiple telnet connections Jibeji 1 4,270 Mar-02-2018, 07:21 PM
Last Post: mpd
  Multithread telnet not working Parallel anna 7 7,459 Feb-05-2018, 01:17 PM
Last Post: anna
  Python telnet script for IP list mangesh 1 60,992 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