Tuesday 16 March 2021

My First Python Script as a Network Engineer

import getpass
import telnetlib

HOST = input("Enter the IP Address of Device: ")
user = input("Enter your account: ")
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")
tn.write(b"terminal len 0\n")
tn.write(b"configure terminal\n")
tn.write(b"hostname amar\n")
tn.write(b"router eigrp 100\n")
tn.write(b"no auto-summary\n")
tn.write(b"network 0.0.0.0\n")
tn.write(b"exit\n")
tn.write(b"exit\n")
tn.write(b"show ip protocol\n")
tn.write(b"show version\n")
tn.write(b"write memory\n")
tn.write(b"exit\n")


print(tn.read_all().decode('ascii'))

Thanks for Reading 

amartechstuff 😊😊

5 comments: