-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
93 lines (78 loc) · 2.6 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import time
import os
import re
from my_switch import *
from arp_manager import *
from netaddr import *
import pandas as pd
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
# assuming that switch passowrd and login is the same for all of them
username = input("Enter username to logon to switch: ")
password = input("Enter password to logon to switch: ")
names = input("Enter endpoints' name source filename: ")
arp_source = input("Enter arp source filename: ")
network = input("Enter you netowrk (network ip/mask, 192.0.0.1/22): ")
ip_ssh = []
ip_telnet = []
# ask for switches ip
rep = "k"
while rep != "q":
rep = input("Enter switch ip with ssh protocol (press 'q' to skip): ")
ip_ssh.append(rep)
rep = "k"
while rep != "q":
rep = input("Enter switch ip with telnet protocol (press 'q' to skip): ")
ip_ssh.append(rep)
net = IPNetwork(network)
manager = arp_manager(net)
# you can either generate arp list from current configuration or load previous one
#mac_ip = manager.generate_arp_table()
mac_ip = manager.load_arp_table(arp_source)
from_list = []
to_list = []
# iterate through ips of ssh protocol switches
for i in ip_ssh:
# create instance class
switch = ssh_switch(i, username, password)
# connect by ssh
switch.est_connection()
# get "up" ports
switch.get_interface_status()
# get mac address per port
int_mac = switch.get_mac_per_interface()
# transalte mac to ip based on arp table
switch.get_ips(mac_ip)
# translate ip to name based on csv table
switch.get_names(names)
# generate output report
switch.generate_csv_info()
# append connections to build graph
for ip in switch.ip_name.values():
from_list.append(switch.ip)
to_list.append(ip)
for i in ip_telnet:
# create instance class
switch = telnet_switch(i, username, password)
# get "up" ports
switch.get_interface_status()
# get mac address per port
switch.get_mac_per_interface()
# transalte mac to ip based on arp table
switch.get_ips(mac_ip)
# translate ip to name based on csv table
switch.get_names(names)
# generate output report
switch.generate_csv_info()
# append connections to build graph
for ip in switch.ip_name.values():
from_list.append(switch.ip)
to_list.append(ip)
# Build a dataframe with your connections
df = pd.DataFrame({'from': from_list, 'to': to_list})
# Build your graph
G = nx.from_pandas_edgelist(df, 'from', 'to')
# Graph with Custom nodes:
nx.draw(G, with_labels=True, node_size=1000, node_color="skyblue", node_shape="s", alpha=0.5, linewidths=40)
plt.show()