IP_list = ["10.1.1.1", "10.1.1.2", "10.1.1.3", "10.1.1.4"] username = "bill" pw = getpass.getpass() vlan_range = range(1, 11) for ip in IP_list: single_ip = telnetlib.Telnet(ip) new_conn = single_ip.open() new_conn.read_until("Username: ") new_conn.write(username + "\n") new_conn.read_until("Password: ") new_conn.write(pw + "\n") new_conn.write("vlan" + str(vlan_range)) new_conn.write("name PYTHON VLAN" + str(vlan_range))
Hi, i'm pretty new to python and I've just written a script then to emulate writing multiple VLANS to different Cisco switches. I'm a Network Engineer but i'm getting more and more into Python now as well because they're starting to become more closely related.I'm just wondering if anyone has any similar experience and could give my script a once over and let me know if they think there are any major issues with it or that it looks okay and will do the job.I'm pretty new to Python so go easy on me haha .Don't worry to much about the Cisco syntax next to read_until(), i'm more wondering if the actual logic of the script looks okay.
Thanks everyone
IP_list = ["10.1.1.1", "10.1.1.2", "10.1.1.3", "10.1.1.4"] username = "bill" pw = getpass.getpass() vlan_range = range(1, 11) for ip in IP_list: single_ip = telnetlib.Telnet(ip) #new_conn = single_ip.open() single_ip.read_until("Username: ") single_ip.write(username + "\n") single_ip.read_until("Password: ") single_ip.write(pw + "\n") single_ip.write("vlan" + str(vlan_range)) single_ip.write("name PYTHON VLAN" + str(vlan_range)) single_ip.close()
Update....i also did that script to because i wasn't sure if the open() function was necessary or not.
No comments:
Post a Comment