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.
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>
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>