python code to telnet to remote session using python telnetlib library

import getpass
import sys
import telnetlib
import time


print("Trying to authenticate to the telnet server")
tn = telnetlib.Telnet('192.168.1.254', timeout=10)

#tn.set_debuglevel(9)

# The first argument is a list of regular expressions,
# either compiled (regex objects) or uncompiled (strings).
# The optional second argument is a timeout, in seconds;
# the default is to block indefinitely.

tn.expect(["Login: ", "login: "], 5)
tn.write('admin' + "\r\n")
tn.expect(["Password: ", "password"], 5)
tn.write('admin123' + "\r\n")

print(" Username and Password Successful.. telnet connection established")
tn.interact()