09-04-2020 07:00 PM
The following python script connects you via telnet protocol to the specified telnet server. It works fine as long as the telnet server prompts for "Username: " and "Password: ". However, If the telnet server does not ask for credentials, this python script will fail.
The question: How would fix the script so that it will also work when the remote telnet server does not ask for username or password?
Below is the python script:
import telnetlib
import getpass
HOST = "192.168.0.101"
user = input("Enter your username: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until(b"Username: ")
tn.write(user.encode() + b"\n")
if password:
tn.read_until(b"Password: ")
tn.write(password.encode() + b"\n")
tn.write(b"terminal length 0\n")
tn.write(b"show version\n")
tn.write(b"exit\n")
output = tn.read_all()
print(output.decode())
09-04-2020 08:06 PM
If the remote server does not require login credentials, then you need to change the script based on the input method.
try using your normal tool putty and secure CRT, and show us how you able to connect to the device ?
09-05-2020 07:13 AM
What about an "if" statement that checks to see if the remote telnet server is requesting a username and a password?
@balaji.bandi wrote:If the remote server does not require login credentials, then you need to change the script based on the input method.
try using your normal tool putty and secure CRT, and show us how you able to connect to the device ?
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide