Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 48 def connected(args):
- 49 username = input("Username: ")
- 50 password = getpass()
- 51
- 52 with open(args.filename) as devices:
- 53 for line in devices:
- 54 deviceaddr = line
- 55
- 56 device = {
- 57 "device_type": "cisco_ios",
- 58 "host": deviceaddr,
- 59 "username": username,
- 60 "password": password,
- 61 }
- 62
- 63 net_connect = ConnectHandler(**device)
- 64 hostname = net_connect.find_prompt()
- 65
- 66 s_status = net_connect.send_command("show int status")
- 67 s_status_split = s_status.split("\n")
- 68 port_rows = s_status_split[2:]
- 69
- 70 list_ports = {}
- 71 for p in port_rows:
- 72 segments = p.split()
- 73 port_name = segments[0]
- 74 #print(port_name)
- 75 start_index = 0
- 76
- 77 for i, value in enumerate(segments):
- 78 if "connect" in value:
- 79 # print(value)
- 80 start_index = i
- 81 break
- 82
- 83 port_data = segments[start_index:]
- 84 list_ports[port_name] = {
- 85 "status": port_data[0],
- 86 "vlan": port_data[1],
- 87 "duplex": port_data[2],
- 88 "speed": port_data[3],
- 89 "type": port_data[4],
- 90 }
- 91 pprint(list_ports)
- 92
- 93 if __name__ == "__main__":
- 94 main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement