Python 3.7 Programming Script For Telnet And Setting IP To Interface (Don't Use It In Real Network)

Python is an open source scripting language, thus used to automate anything!! I have started learning python from its complete basics and then gradually turned up writing scripts to automate stuff around me. To automate things in python, you can simply write scripts.




import getpass
import telnetlib

HOST=input("Enter IP of Router :")
user=input("Enter The Username :")
password=getpass.getpass()

tn=telnetlib.Telnet(HOST)

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

tn.write(b"enable\n")
print("Enter Enable Password\n")
enable=getpass.getpass()

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

tn.write(b"conf t\n")
tn.write(b"int f0/0\n")
ip=input("Enter New IP address with Subnet Mask :")
tn.write(ip.encode('ascii')+b"\n")
tn.write(b"do write\n")
tn.write(b"End\n")
tn.write(b"Exit\n")
print("Done")


print(tn.read_all().decode('ascii'))
Post a Comment (0)
Previous Post Next Post

Advertisment