Added BGP & OSPF info.

This commit is contained in:
Sean Corrigan 2020-12-15 20:14:07 -05:00
parent 23304fcb63
commit f6d564fb26
5 changed files with 388 additions and 73 deletions

View File

@ -46,8 +46,6 @@ configs/R3
configs/DLS1 configs/DLS1
,Loopback0,10.1.211.1,255.255.255.255,2001:DB8:CAFE:2110::D1/128, ,Anchor ,Loopback0,10.1.211.1,255.255.255.255,2001:DB8:CAFE:2110::D1/128, ,Anchor
,Port-channel1,-,-,-, ,- - - - - -
,Port-channel10,-,-,-, ,Channel to DLS2 ,Port-channel10,-,-,-, ,Channel to DLS2
,GigabitEthernet0/0,-,-,-, ,Channel to DLS2 ,GigabitEthernet0/0,-,-,-, ,Channel to DLS2
@ -68,20 +66,6 @@ configs/DLS1
,GigabitEthernet2/0,10.1.2.1,255.255.255.252,2001:DB8:CAFE:20::D1/64, ,GE to R1 ,GigabitEthernet2/0,10.1.2.1,255.255.255.252,2001:DB8:CAFE:20::D1/64, ,GE to R1
,Vlan1,SHUTDOWN
,Vlan99,10.1.99.252,255.255.255.0,2001:DB8:CAFE:99::D1/64, ,- - - - - -
,Vlan100,10.1.100.252,255.255.255.0,2001:DB8:CAFE:100::D1/64, ,- - - - - -
,Vlan110,10.1.110.252,255.255.255.0,2001:DB8:CAFE:110::D1/64, ,- - - - - -
,Vlan120,10.1.120.252,255.255.255.0,2001:DB8:CAFE:120::D1/64, ,- - - - - -
,Vlan200,10.1.200.252,255.255.255.0,2001:DB8:CAFE:200::D1/64, ,- - - - - -
,Vlan300,10.1.30.252,255.255.255.0,2001:DB8:CAFE:300::D1/64, ,- - - - - -
configs/DLS2 configs/DLS2
,Loopback0,10.1.212.1,255.255.255.255,2001:DB8:CAFE:2120::D2/128, ,Anchor ,Loopback0,10.1.212.1,255.255.255.255,2001:DB8:CAFE:2120::D2/128, ,Anchor
@ -107,20 +91,6 @@ configs/DLS2
,GigabitEthernet2/0,10.1.2.13,255.255.255.252,2001:DB8:CAFE:212::D2/64, ,GE to R3 ,GigabitEthernet2/0,10.1.2.13,255.255.255.252,2001:DB8:CAFE:212::D2/64, ,GE to R3
,Vlan1,SHUTDOWN
,Vlan99,10.1.99.253,255.255.255.0,2001:DB8:CAFE:99::D2/64, ,- - - - - -
,Vlan100,10.1.100.253,255.255.255.0,2001:DB8:CAFE:100::D2/64, ,- - - - - -
,Vlan110,10.1.110.253,255.255.255.0,2001:DB8:CAFE:110::D2/64, ,- - - - - -
,Vlan120,10.1.120.253,255.255.255.0,2001:DB8:CAFE:120::D2/64, ,- - - - - -
,Vlan200,10.1.200.253,255.255.255.0,2001:DB8:CAFE:200::D2/64, ,- - - - - -
,Vlan300,10.1.30.253,255.255.255.0,2001:DB8:CAFE:300::D2/64, ,- - - - - -
configs/ALS1 configs/ALS1
,Port-channel1,-,-,-, ,Channel to DLS1 ,Port-channel1,-,-,-, ,Channel to DLS1
@ -136,17 +106,3 @@ configs/ALS1
,GigabitEthernet1/0,-,-,-, ,To PC-B ,GigabitEthernet1/0,-,-,-, ,To PC-B
,Vlan1,SHUTDOWN
,Vlan99,10.1.99.251,255.255.255.0,2001:DB8:CAFE:99::A1/64, ,- - - - - -
,Vlan100,10.1.100.251,255.255.255.0,2001:DB8:CAFE:100::A1/64, ,- - - - - -
,Vlan110,10.1.110.251,255.255.255.0,2001:DB8:CAFE:110::A1/64, ,- - - - - -
,Vlan120,10.1.120.251,255.255.255.0,2001:DB8:CAFE:120::A1/64, ,- - - - - -
,Vlan200,10.1.200.251,255.255.255.0,2001:DB8:CAFE:200::A1/64, ,- - - - - -
,Vlan300,10.1.30.251,255.255.255.0,2001:DB8:CAFE:300::A1/64, ,- - - - - -

1 configs/R1
46 ,Loopback0,10.1.212.1,255.255.255.255,2001:DB8:CAFE:2120::D2/128, ,Anchor ,GigabitEthernet1/1,SHUTDOWN
47 ,Port-channel2,-,-,-, ,Channel to ALS1 ,GigabitEthernet1/2,SHUTDOWN
48 ,Port-channel10,-,-,-, ,Channel to DLS1 ,GigabitEthernet1/3,SHUTDOWN
,GigabitEthernet0/0,-,-,-, ,Channel to DLS1
,GigabitEthernet0/1,-,-,-, ,Channel to DLS1
49 ,GigabitEthernet0/2,-,-,-, ,Channel to ALS1 ,GigabitEthernet2/0,10.1.2.13,255.255.255.252,2001:DB8:CAFE:212::D2/64, ,GE to R3
50 ,GigabitEthernet0/3,-,-,-, ,Channel to ALS1 configs/ALS1
51 ,GigabitEthernet1/0,SHUTDOWN ,Port-channel1,-,-,-, ,Channel to DLS1
66
67
68
,GigabitEthernet0/3,-,-,-, ,Channel to DLS2
,GigabitEthernet1/0,-,-,-, ,To PC-B
,Vlan1,SHUTDOWN
,Vlan99,10.1.99.251,255.255.255.0,2001:DB8:CAFE:99::A1/64, ,- - - - - -
,Vlan100,10.1.100.251,255.255.255.0,2001:DB8:CAFE:100::A1/64, ,- - - - - -
,Vlan110,10.1.110.251,255.255.255.0,2001:DB8:CAFE:110::A1/64, ,- - - - - -
,Vlan120,10.1.120.251,255.255.255.0,2001:DB8:CAFE:120::A1/64, ,- - - - - -
,Vlan200,10.1.200.251,255.255.255.0,2001:DB8:CAFE:200::A1/64, ,- - - - - -
,Vlan300,10.1.30.251,255.255.255.0,2001:DB8:CAFE:300::A1/64, ,- - - - - -
69
70
71
91
92
93
94
95
96
106
107
108

149
BGPinfo.csv Normal file
View File

@ -0,0 +1,149 @@
BGP INFO FOR: configs/R1,AS: 1.0.0.1
GLOBAL
,Advertised Nets:
,Neighbours:
,192.168.3.1,65501
,209.165.200.226,65502
,Neighbours w/ auth:
,192.168.3.1,ENABLED
,209.165.200.226,ENABLED
ADDRESS-FAMILY IPV4
,Advertised Nets:
,10.1.0.0,255.255.0.0
,192.168.1.1,255.255.255.255
,209.165.200.224,255.255.255.252
,Neighbours:
,192.168.3.1,ACTIVATED
,209.165.200.226,ACTIVATED
ADDRESS-FAMILY IPV6
,Advertised Nets:
,2001:DB8:CAFE::/48
,2001:DB8:CAFE:201::1/128
,2001:DB8:FEED:10::/126
,ABCD::/16
,Neighbours:
,192.168.3.1,ACTIVATED
,209.165.200.226,ACTIVATED
BGP INFO FOR: configs/R2,AS: 2.0.0.2
GLOBAL
,Advertised Nets:
ADDRESS-FAMILY IPV4 VRF VPN_A
,Advertised Nets:
,0.0.0.0
,2.2.2.2,255.255.255.255
,Neighbours:
,209.165.200.225,65501
,209.165.200.225,ACTIVATED
,Neighbours w/ auth:
,209.165.200.225,ENABLED
ADDRESS-FAMILY IPV6 VRF VPN_A
,Advertised Nets:
,::/0
,2001:DB8:FEED:222::2/128
,Neighbours:
,209.165.200.225,65501
,209.165.200.225,ACTIVATED
,Neighbours w/ auth:
,209.165.200.225,ENABLED
ADDRESS-FAMILY IPV4 VRF VPN_B
,Advertised Nets:
,0.0.0.0
,2.2.2.2,255.255.255.255
,Neighbours:
,209.165.200.221,65501
,209.165.200.221,ACTIVATED
,Neighbours w/ auth:
,209.165.200.221,ENABLED
ADDRESS-FAMILY IPV6 VRF VPN_B
,Advertised Nets:
,::/0
,2001:DB8:FEED:222::2/128
,Neighbours:
,209.165.200.221,65501
,209.165.200.221,ACTIVATED
,Neighbours w/ auth:
,209.165.200.221,ENABLED
BGP INFO FOR: configs/R3,AS: 3.0.0.3
GLOBAL
,Advertised Nets:
,Neighbours:
,192.168.1.1,65501
,209.165.200.222,65503
,Neighbours w/ auth:
,192.168.1.1,ENABLED
,209.165.200.222,ENABLED
ADDRESS-FAMILY IPV4
,Advertised Nets:
,10.1.0.0,255.255.0.0
,192.168.3.1,255.255.255.255
,209.165.200.220,255.255.255.252
,Neighbours:
,192.168.1.1,ACTIVATED
,209.165.200.222,ACTIVATED
ADDRESS-FAMILY IPV6
,Advertised Nets:
,2001:DB8:CAFE::/48
,2001:DB8:CAFE:203::1/128
,2001:DB8:FEED:14::/126
,ABCD::/16
,Neighbours:
,192.168.1.1,ACTIVATED
,209.165.200.222,ACTIVATED
1 BGP INFO FOR: configs/R1,AS: 1.0.0.1
2 GLOBAL
3 ,Advertised Nets:
4 ,Neighbours:
5 ,192.168.3.1,65501
6 ,209.165.200.226,65502
7 ,Neighbours w/ auth:
8 ,192.168.3.1,ENABLED
9 ,209.165.200.226,ENABLED
10 ADDRESS-FAMILY IPV4
11 ,Advertised Nets:
12 ,10.1.0.0,255.255.0.0
13 ,192.168.1.1,255.255.255.255
14 ,209.165.200.224,255.255.255.252
15 ,Neighbours:
16 ,192.168.3.1,ACTIVATED
17 ,209.165.200.226,ACTIVATED
18 ADDRESS-FAMILY IPV6
19 ,Advertised Nets:
20 ,2001:DB8:CAFE::/48
21 ,2001:DB8:CAFE:201::1/128
22 ,2001:DB8:FEED:10::/126
23 ,ABCD::/16
24 ,Neighbours:
25 ,192.168.3.1,ACTIVATED
26 ,209.165.200.226,ACTIVATED
27 BGP INFO FOR: configs/R2,AS: 2.0.0.2
28 GLOBAL
29 ,Advertised Nets:
30 ADDRESS-FAMILY IPV4 VRF VPN_A
31 ,Advertised Nets:
32 ,0.0.0.0
33 ,2.2.2.2,255.255.255.255
34 ,Neighbours:
35 ,209.165.200.225,65501
36 ,209.165.200.225,ACTIVATED
37 ,Neighbours w/ auth:
38 ,209.165.200.225,ENABLED
39 ADDRESS-FAMILY IPV6 VRF VPN_A
40 ,Advertised Nets:
41 ,::/0
42 ,2001:DB8:FEED:222::2/128
43 ,Neighbours:
44 ,209.165.200.225,65501
45 ,209.165.200.225,ACTIVATED
46 ,Neighbours w/ auth:
47 ,209.165.200.225,ENABLED
48 ADDRESS-FAMILY IPV4 VRF VPN_B
49 ,Advertised Nets:
50 ,0.0.0.0
51 ,2.2.2.2,255.255.255.255
52 ,Neighbours:
53 ,209.165.200.221,65501
54 ,209.165.200.221,ACTIVATED
55 ,Neighbours w/ auth:
56 ,209.165.200.221,ENABLED
57 ADDRESS-FAMILY IPV6 VRF VPN_B
58 ,Advertised Nets:
59 ,::/0
60 ,2001:DB8:FEED:222::2/128
61 ,Neighbours:
62 ,209.165.200.221,65501
63 ,209.165.200.221,ACTIVATED
64 ,Neighbours w/ auth:
65 ,209.165.200.221,ENABLED
66 BGP INFO FOR: configs/R3,AS: 3.0.0.3
67 GLOBAL
68 ,Advertised Nets:
69 ,Neighbours:
70 ,192.168.1.1,65501
71 ,209.165.200.222,65503
72 ,Neighbours w/ auth:
73 ,192.168.1.1,ENABLED
74 ,209.165.200.222,ENABLED
75 ADDRESS-FAMILY IPV4
76 ,Advertised Nets:
77 ,10.1.0.0,255.255.0.0
78 ,192.168.3.1,255.255.255.255
79 ,209.165.200.220,255.255.255.252
80 ,Neighbours:
81 ,192.168.1.1,ACTIVATED
82 ,209.165.200.222,ACTIVATED
83 ADDRESS-FAMILY IPV6
84 ,Advertised Nets:
85 ,2001:DB8:CAFE::/48
86 ,2001:DB8:CAFE:203::1/128
87 ,2001:DB8:FEED:14::/126
88 ,ABCD::/16
89 ,Neighbours:
90 ,192.168.1.1,ACTIVATED
91 ,209.165.200.222,ACTIVATED

58
OSPFinfo.csv Normal file
View File

@ -0,0 +1,58 @@
OSPF INFO FOR: configs/R1,Router-ID: 1.0.0.1
,Network Redistribute:
,10.1.2.0,0.0.0.3,0
,192.168.1.1,0.0.0.0,0
,Active Interfaces:
,GigabitEthernet0/1
OSPF INFO FOR: configs/R3,Router-ID: 3.0.0.3
,Network Redistribute:
,10.1.2.12,0.0.0.3,0
,192.168.3.1,0.0.0.0,0
,Active Interfaces:
,GigabitEthernet0/1
OSPF INFO FOR: configs/DLS1,Router-ID: 1.1.1.1
,Network Redistribute:
,10.1.2.0,0.0.0.3,0
,10.1.30.0,0.0.0.255,0
,10.1.99.0,0.0.0.255,1
,10.1.100.0,0.0.0.255,1
,10.1.110.0,0.0.0.255,1
,10.1.120.0,0.0.0.255,1
,10.1.200.0,0.0.0.255,1
,10.1.211.1,0.0.0.0,0
,Active Interfaces:
,GigabitEthernet2/0
,Vlan300
OSPF INFO FOR: configs/DLS2,Router-ID: 2.2.2.2
,Network Redistribute:
,10.1.2.12,0.0.0.3,0
,10.1.30.0,0.0.0.255,0
,10.1.99.0,0.0.0.255,1
,10.1.100.0,0.0.0.255,1
,10.1.110.0,0.0.0.255,1
,10.1.120.0,0.0.0.255,1
,10.1.200.0,0.0.0.255,1
,10.1.212.1,0.0.0.0,0
,Active Interfaces:
,GigabitEthernet2/0
,Vlan300
1 OSPF INFO FOR: configs/R1,Router-ID: 1.0.0.1
2 ,Network Redistribute:
3 ,10.1.2.0,0.0.0.3,0
4 ,192.168.1.1,0.0.0.0,0
5 ,Active Interfaces:
6 ,GigabitEthernet0/1
7 OSPF INFO FOR: configs/R3,Router-ID: 3.0.0.3
8 ,Network Redistribute:
9 ,10.1.2.12,0.0.0.3,0
10 ,192.168.3.1,0.0.0.0,0
11 ,Active Interfaces:
12 ,GigabitEthernet0/1
13 OSPF INFO FOR: configs/DLS1,Router-ID: 1.1.1.1
14 ,Network Redistribute:
15 ,10.1.2.0,0.0.0.3,0
16 ,10.1.30.0,0.0.0.255,0
17 ,10.1.99.0,0.0.0.255,1
18 ,10.1.100.0,0.0.0.255,1
19 ,10.1.110.0,0.0.0.255,1
20 ,10.1.120.0,0.0.0.255,1
21 ,10.1.200.0,0.0.0.255,1
22 ,10.1.211.1,0.0.0.0,0
23 ,Active Interfaces:
24 ,GigabitEthernet2/0
25 ,Vlan300
26 OSPF INFO FOR: configs/DLS2,Router-ID: 2.2.2.2
27 ,Network Redistribute:
28 ,10.1.2.12,0.0.0.3,0
29 ,10.1.30.0,0.0.0.255,0
30 ,10.1.99.0,0.0.0.255,1
31 ,10.1.100.0,0.0.0.255,1
32 ,10.1.110.0,0.0.0.255,1
33 ,10.1.120.0,0.0.0.255,1
34 ,10.1.200.0,0.0.0.255,1
35 ,10.1.212.1,0.0.0.0,0
36 ,Active Interfaces:
37 ,GigabitEthernet2/0
38 ,Vlan300

View File

@ -1,4 +1,5 @@
configs/DLS1 configs/DLS1
,switchport,SHUTDOWN
,Vlan1,SHUTDOWN ,Vlan1,SHUTDOWN
,Vlan99,10.1.99.252,255.255.255.0,2001:DB8:CAFE:99::D1/64, ,110,ACTIVE,YES ,Vlan99,10.1.99.252,255.255.255.0,2001:DB8:CAFE:99::D1/64, ,110,ACTIVE,YES
,Vlan100,10.1.100.252,255.255.255.0,2001:DB8:CAFE:100::D1/64, ,100,STANDBY,NO ,Vlan100,10.1.100.252,255.255.255.0,2001:DB8:CAFE:100::D1/64, ,100,STANDBY,NO
@ -7,6 +8,7 @@ configs/DLS1
,Vlan200,10.1.200.252,255.255.255.0,2001:DB8:CAFE:200::D1/64, ,100,STANDBY,NO ,Vlan200,10.1.200.252,255.255.255.0,2001:DB8:CAFE:200::D1/64, ,100,STANDBY,NO
,Vlan300,10.1.30.252,255.255.255.0,2001:DB8:CAFE:300::D1/64, ,100,STANDBY,NO ,Vlan300,10.1.30.252,255.255.255.0,2001:DB8:CAFE:300::D1/64, ,100,STANDBY,NO
configs/DLS2 configs/DLS2
,switchport,SHUTDOWN
,Vlan1,SHUTDOWN ,Vlan1,SHUTDOWN
,Vlan99,10.1.99.253,255.255.255.0,2001:DB8:CAFE:99::D2/64, ,100,STANDBY,NO ,Vlan99,10.1.99.253,255.255.255.0,2001:DB8:CAFE:99::D2/64, ,100,STANDBY,NO
,Vlan100,10.1.100.253,255.255.255.0,2001:DB8:CAFE:100::D2/64, ,110,ACTIVE,YES ,Vlan100,10.1.100.253,255.255.255.0,2001:DB8:CAFE:100::D2/64, ,110,ACTIVE,YES

1 configs/DLS1
2 ,switchport,SHUTDOWN
3 ,Vlan1,SHUTDOWN
4 ,Vlan99,10.1.99.252,255.255.255.0,2001:DB8:CAFE:99::D1/64, ,110,ACTIVE,YES
5 ,Vlan100,10.1.100.252,255.255.255.0,2001:DB8:CAFE:100::D1/64, ,100,STANDBY,NO
8 ,Vlan200,10.1.200.252,255.255.255.0,2001:DB8:CAFE:200::D1/64, ,100,STANDBY,NO
9 ,Vlan300,10.1.30.252,255.255.255.0,2001:DB8:CAFE:300::D1/64, ,100,STANDBY,NO
10 configs/DLS2
11 ,switchport,SHUTDOWN
12 ,Vlan1,SHUTDOWN
13 ,Vlan99,10.1.99.253,255.255.255.0,2001:DB8:CAFE:99::D2/64, ,100,STANDBY,NO
14 ,Vlan100,10.1.100.253,255.255.255.0,2001:DB8:CAFE:100::D2/64, ,110,ACTIVE,YES

202
main.py
View File

@ -1,6 +1,12 @@
## Stuff for streamlining ## Stuff for streamlining
def splitInterfaces(filename, searchterms = ['interface GigabitEthernet', 'interface Loopback','interface Port-channel', 'interface Vlan']):
## Split out a "category" by what the header would contain.
def splitInterfaces(filename, searchterms, ignorelist = []):
## TODO ###
## ##
deviceDic = {} # All interfaces deviceDic = {} # All interfaces
interfaceDic = [] # Single interface interfaceDic = [] # Single interface
@ -8,12 +14,15 @@ def splitInterfaces(filename, searchterms = ['interface GigabitEthernet', 'inter
device = open(filename, 'r') device = open(filename, 'r')
bit = 0 bit = 0
for line in device: # Read each line for line in device: # Read each line
if len(line.split(" ")) != 2 and bit == 0: # If another type of Gigabit ethernet config # if len(line.split(" ")) != 2 and bit == 0: # If another type of Gigabit ethernet config
continue # ignore # continue # ignore
## Actual Logic ## Actual Logic
if ' !' in line and bit != 0: # Skip a sub-information ending
interfaceDic.append(" !")
continue
if '!' in line and bit != 0: # Comment or end of interface if '!' in line and bit != 0: # Comment or end of interface
# input(interfaceDic) # input(interfaceDic)
if " shutdown\n" in interfaceDic: if " shutdown\n" in interfaceDic and "no shut" not in interfaceDic:
# input(bit) # input(bit)
interfaceDic = 'shutdown' interfaceDic = 'shutdown'
deviceDic[bit] = interfaceDic # push to the main dict deviceDic[bit] = interfaceDic # push to the main dict
@ -22,11 +31,41 @@ def splitInterfaces(filename, searchterms = ['interface GigabitEthernet', 'inter
continue continue
if bit != 0: # If we are traversing an interface record the info if bit != 0: # If we are traversing an interface record the info
interfaceDic.append(line) interfaceDic.append(line)
## see if we found the start of a new section we want
for term in searchterms: # each of the terms we are looking for in 'searchterms' list for term in searchterms: # each of the terms we are looking for in 'searchterms' list
if term in line: # If we find a term line if term in line: # If we find a term line
bit = str(line.split(" ")[1]) # Set the traversing bit to the name bit = str(line.split(" ")[1]) # Set the traversing bit to the name
## Add fix for bgp et all
if "bgp" in line.split(" "):
bit = str(line.split(" ")[2])
## Sanity check
for ignore in ignorelist: # each of the terms we are told to ignore
if ignore in line: # if a ignore term is in our line
bit = 0
continue # dont traverse this
return deviceDic return deviceDic
def splitsubInterfaces(subDict, ignorelist = []): # menus within menus
attr = [] # this is going to be our sub lines for each of our parent interfaces
for x in subDict: ## Add the list from dict to db
attr = subDict[x]
## Now split into 3 or whatever dicts
subs = {};
bit = 'global' # Oustide of address family etcs
subs[bit] = [attr[0]]
for line in attr:
if "!" in line:
bit = 0
continue
if bit == 0:
bit = line.replace("\n", "")
if bit != 0 and bit in subs:
subs[bit].append(line.replace("\n", ""))
if bit != 0 and bit not in subs:
subs[bit] = []
return subs
def searchList(item, attributeList): def searchList(item, attributeList):
for x in attributeList: for x in attributeList:
if 'link-local' in x: if 'link-local' in x:
@ -37,6 +76,20 @@ def searchList(item, attributeList):
return x return x
return '- - - - - - description \n' return '- - - - - - description \n'
def searchMultiple(item, attributeList, ignore=[]): # find multiple instances of a word, eg. network statements
found = []; bit = False
for x in attributeList:
if item in x:
for i in ignore:
if i in ignore:
continue
bit = True # Trigger the found 'bit'
found.append(x)
if bit:
return found
else:
return '- - - - - - description \n'
def generateVlanCSV(filenamesList): # Records the VLAN SVIs to a file def generateVlanCSV(filenamesList): # Records the VLAN SVIs to a file
output = open("Vlans.csv", "w+") output = open("Vlans.csv", "w+")
@ -44,13 +97,6 @@ def generateVlanCSV(filenamesList): # Records the VLAN SVIs to a file
searchterms = ['interface Vlan', 'vlan '] searchterms = ['interface Vlan', 'vlan ']
vlans = splitInterfaces(filename, searchterms) vlans = splitInterfaces(filename, searchterms)
# for x in vlans:
# print('*********')
# print(x)
# print('--')
# print(vlans[x])
# print('*********')
output.write(filename.replace(".txt", "\n")) output.write(filename.replace(".txt", "\n"))
# Write the ports out to csv # Write the ports out to csv
@ -62,14 +108,7 @@ def generateVlanCSV(filenamesList): # Records the VLAN SVIs to a file
if 'Vlan' not in port: # Only Deal with the SVIs right now if 'Vlan' not in port: # Only Deal with the SVIs right now
continue continue
# Other catchs ## Write normal VLAN output
# Vlan99
# [' ip address 10.1.99.252 255.255.255.0\n', ' no ip proxy-arp\n', ' standby 99 ip 10.1.99.254\n', ' standby
# 99 priority 110\n', ' standby 99 preempt\n', ' standby 99 track 23 decrement 20\n', ' ipv6 address FE80::D1
# link-local\n', ' ipv6 address 2001:DB8:CAFE:99::D1/64\n', ' no shutdown\n']
# Write normal VLAN output
try: try:
ipv4 = searchList("ip address", vlans[port]).replace("\n", "").split(" ") ipv4 = searchList("ip address", vlans[port]).replace("\n", "").split(" ")
ipv6 = searchList("ipv6 address", vlans[port]).split(" ")[3].replace("\n", "") ipv6 = searchList("ipv6 address", vlans[port]).split(" ")[3].replace("\n", "")
@ -93,7 +132,7 @@ def generateVlanCSV(filenamesList): # Records the VLAN SVIs to a file
def generateAddressCSV(filenamesList): def generateAddressCSV(filenamesList):
output = open("Addressing.csv", "w+") output = open("Addressing.csv", "w+")
for filename in filenamesList: for filename in filenamesList:
interfaces = splitInterfaces(filename) interfaces = splitInterfaces(filename, ['interface GigabitEthernet', 'interface Loopback','interface Port-channel'], ['ssh', 'source-interface', ])
output.write(filename.replace(".txt", "\n")) output.write(filename.replace(".txt", "\n"))
# Write the ports out to csv # Write the ports out to csv
@ -107,20 +146,131 @@ def generateAddressCSV(filenamesList):
ipv4 = searchList("ip address", interfaces[port]).replace("\n", "").split(" ") ipv4 = searchList("ip address", interfaces[port]).replace("\n", "").split(" ")
ipv6 = searchList("ipv6 address", interfaces[port]).split(" ")[3].replace("\n", "") ipv6 = searchList("ipv6 address", interfaces[port]).split(" ")[3].replace("\n", "")
desc = searchList("description", interfaces[port]).replace(" description ", "") desc = searchList("description", interfaces[port]).replace(" description ", "")
output.write(",{},{},{},{}, ,{}\n".format(port.replace("\n", ""),ipv4[3],ipv4[4],ipv6,desc)) if '- - - - - -' in desc and '-' in ipv4[2]:
continue
else:
output.write(",{},{},{},{}, ,{}\n".format(port.replace("\n", ""),ipv4[3],ipv4[4],ipv6,desc))
except: except:
pass pass
output.close()
def generateBGPcsv(filenamesList):
output = open("BGPinfo.csv", "w+")
searchterms = ["router bgp"]
ignorelist = ['exec']
for filename in filenamesList:
BGPattr = splitInterfaces(filename, searchterms, ignorelist)
BGPattrS = splitsubInterfaces(BGPattr, [''])
for x in BGPattrS:
ASNUM = (BGPattrS[x][1].lstrip().split(" ")[2])
break
output.write("\n\nBGP INFO FOR: {},AS: {}\n\n".format(filename.replace(".txt", ""), ASNUM))
# Write the info out to csv
# input(BGPattrS)
for ASnum in BGPattrS:
## Record Neighbours
neighbors = searchMultiple('neighbor', BGPattrS[ASnum])
advernet = searchMultiple('network', BGPattrS[ASnum])
remoteNei = []
passNei = []
source = []
### Catch anything and sort where we need it
for x in neighbors:
# print(x)
if 'remote-as' in x or 'activate' in x:
remoteNei.append(x)
if 'password' in x:
passNei.append(x)
## TODO - maybe remove all that found a home then
# add a coloum with extra attributes
output.write("{}".format(ASnum.lstrip().upper()))
# Add remote ASes to csv
if advernet != []:
output.write("\n,Advertised Nets:\n")
for x in advernet:
if 'description' in advernet:
continue
properties = x.lstrip().split(" ")
if len(properties) < 3: # IPV6
output.write(",{}\n".format(properties[1]))
else:
output.write(",{},{}\n".format(properties[1],properties[3]))
output.write("\n")
if remoteNei != []:
output.write("\n,Neighbours:\n")
for x in remoteNei:
properties = x.lstrip().split(" ")
if len(properties) < 4:
output.write(",{},ACTIVATED\n".format(properties[1]))
else:
output.write(",{},{}\n".format(properties[1],properties[3]))
output.write("\n")
if passNei != []:
output.write("\n,Neighbours w/ auth:\n")
for x in passNei:
properties = x.lstrip().split(" ")
output.write(",{},ENABLED\n".format(properties[1]))
output.write("\n")
output.close() output.close()
def generateOSPFcsv(filenamesList):
output = open("OSPFinfo.csv", "w+")
searchterms = ["router ospf"]
ignorelist = ['exec']
for filename in filenamesList:
ospf = splitInterfaces(filename, searchterms, ignorelist)
try:
routerid = ospf['ospf'][0].lstrip().split(" ")[1].replace("\n", "")
except: continue
output.write("\n\nOSPF INFO FOR: {},Router-ID: {}\n".format(filename.replace(".txt", ""),routerid))
output.write("\n,Network Redistribute:\n")
##
network = searchMultiple('network', ospf['ospf'])
for statement in network:
statement = statement.lstrip().replace("\n", "").split(" ")
output.write(",{},{},{}\n".format(statement[1],statement[2],statement[4]))
output.write("\n")
output.write("\n,Active Interfaces:\n")
##
active = searchMultiple('no passive-interface', ospf['ospf'])
for interface in active:
interface = interface.lstrip().replace("\n", "").split(" ")
output.write(",{}\n".format(interface[2]))
output.close()
## Location of the configs ## Location of the configs
# Sorted by device type just incase # Sorted by device type just incase
RouterConfigs = ['configs/R1.txt','configs/R2.txt','configs/R3.txt'] RouterConfigs = ['configs/R1.txt','configs/R2.txt','configs/R3.txt']
SwitchConfigs = ['configs/DLS1.txt', 'configs/DLS2.txt', 'configs/ALS1.txt'] SwitchConfigs = ['configs/DLS1.txt', 'configs/DLS2.txt', 'configs/ALS1.txt']
# MasterList AllDevices = RouterConfigs + SwitchConfigs # MasterList
AllDevices = RouterConfigs + SwitchConfigs
# Output Addressing Table ## Output Addressing Table
# generateAddressCSV(AllDevices) generateAddressCSV(AllDevices)
# Output Vlan Table ## Output Vlan Table
generateVlanCSV(SwitchConfigs) generateVlanCSV(SwitchConfigs)
## Output BGP Table
generateBGPcsv(RouterConfigs)
## Output OSPF Table
generateOSPFcsv(AllDevices)
## Output EIGRP Table
# Seems kinda just basicy