Python Forum
Python script hangs after entering username to remote login using telnetlib
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python script hangs after entering username to remote login using telnetlib
#1
I am trying to login to my network power control switch and run commands in it using python telnetlib script, after running the script it displays "enter the username" in the output terminal for which i enter the switch username and the script hangs at that point without asking for password and proceeding further. kindly help me in proceeding further ..pasted the script below.

import getpass
import sys
import telnetlib
HOST = "192.168.8.8"
PORT=22 
TIMEOUT=10
user = input("Enter your username : ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until(b"User Name : ")
tn.write(user.encode('ascii') + b"\n")
if password:
    tn.read_until(b"Password  : ")
    tn.write(password.encode('ascii') + b"\n")
tn.write("tcpip\n")
tn.write("exit\n")
print(tn.read_all())
manually i am able to login into the device, pasted the login screen of the device below for more clarity

User Name : apc Password : ***

Schneider Electric Network Management Card AOS v6.4.6
Name : apcE2FA28 Date : 09/05/2018 Contact : Unknown Time : 21:56:52 Location : Unknown User : Super User Up Time : 0 Days 0 Hours 7 Minutes Stat : P+ N4+ N6+ A+

Type ? for command listing Use tcpip command for IP address(-i), subnet(-s), and gateway(-g)

apc>tcpip E000: Success

Active IPv4 Settings
Active IPv4 Address: 192.168.8.8 Active IPv4 Subnet Mask: 255.255.255.0 Active IPv4 Gateway: 0.0.0.0

Manually Configured IPv4 Settings
IPv4: enabled Manual Settings: enabled

IPv4 Address: 192.168.8.8 Subnet Mask: 255.255.255.0 Gateway: 0.0.0.0 MAC Address: 00 C0 B7 E2 FA 28 Domain Name: example.com Host Name: apcE2FA28

apc>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Post Request containing username/password using python for jwt anna 1 4,045 Oct-18-2022, 04:06 PM
Last Post: anna
  telnetlib. configure hostnames lado 1 2,931 May-30-2020, 01:49 PM
Last Post: matya0403
  telnetlib timeout kerzol81 0 3,411 Sep-12-2019, 08:38 AM
Last Post: kerzol81
  Telnetlib reading output petterg 1 11,293 Jul-06-2019, 12:08 PM
Last Post: searching1
  How to run local python script to remote machine without sending krishna1989 1 8,346 Feb-21-2019, 05:18 PM
Last Post: marienbad
  Pexpect - Python 3.7 - Unable to get my script past the login stage lgreenjr 3 3,882 Nov-01-2018, 10:49 PM
Last Post: lgreenjr
  telnetlib timeout expections handling issue anna 0 7,806 Jun-08-2018, 06:28 AM
Last Post: anna
  python telnetlib prompt matching issue anna 0 3,996 Jan-30-2018, 05:34 PM
Last Post: anna
  telnetlib.Telnet timeout issue.. taking much time anna 1 8,274 Jan-19-2018, 01:52 PM
Last Post: devs4p

Forum Jump:

User Panel Messages

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