diff --git a/Addressing.csv b/Addressing.csv index 8d7d6b9..b1d99c2 100644 --- a/Addressing.csv +++ b/Addressing.csv @@ -46,8 +46,6 @@ configs/R3 configs/DLS1 ,Loopback0,10.1.211.1,255.255.255.255,2001:DB8:CAFE:2110::D1/128, ,Anchor -,Port-channel1,-,-,-, ,- - - - - - - ,Port-channel10,-,-,-, ,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 -,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 ,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 -,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 ,Port-channel1,-,-,-, ,Channel to DLS1 @@ -136,17 +106,3 @@ configs/ALS1 ,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, ,- - - - - - - diff --git a/BGPinfo.csv b/BGPinfo.csv new file mode 100644 index 0000000..9eae7af --- /dev/null +++ b/BGPinfo.csv @@ -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 + + diff --git a/OSPFinfo.csv b/OSPFinfo.csv new file mode 100644 index 0000000..6792983 --- /dev/null +++ b/OSPFinfo.csv @@ -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 diff --git a/Vlans.csv b/Vlans.csv index febb2e0..f36d1e7 100644 --- a/Vlans.csv +++ b/Vlans.csv @@ -1,4 +1,5 @@ configs/DLS1 +,switchport,SHUTDOWN ,Vlan1,SHUTDOWN ,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 @@ -7,6 +8,7 @@ configs/DLS1 ,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 configs/DLS2 +,switchport,SHUTDOWN ,Vlan1,SHUTDOWN ,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 diff --git a/main.py b/main.py index 3663802..0339bed 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,12 @@ ## 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 interfaceDic = [] # Single interface @@ -8,12 +14,15 @@ def splitInterfaces(filename, searchterms = ['interface GigabitEthernet', 'inter device = open(filename, 'r') bit = 0 for line in device: # Read each line - if len(line.split(" ")) != 2 and bit == 0: # If another type of Gigabit ethernet config - continue # ignore + # if len(line.split(" ")) != 2 and bit == 0: # If another type of Gigabit ethernet config + # continue # ignore ## 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 # input(interfaceDic) - if " shutdown\n" in interfaceDic: + if " shutdown\n" in interfaceDic and "no shut" not in interfaceDic: # input(bit) interfaceDic = 'shutdown' deviceDic[bit] = interfaceDic # push to the main dict @@ -22,11 +31,41 @@ def splitInterfaces(filename, searchterms = ['interface GigabitEthernet', 'inter continue if bit != 0: # If we are traversing an interface record the info 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 if term in line: # If we find a term line 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 +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): for x in attributeList: if 'link-local' in x: @@ -37,6 +76,20 @@ def searchList(item, attributeList): return x 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 output = open("Vlans.csv", "w+") @@ -44,13 +97,6 @@ def generateVlanCSV(filenamesList): # Records the VLAN SVIs to a file searchterms = ['interface Vlan', 'vlan '] vlans = splitInterfaces(filename, searchterms) - # for x in vlans: - # print('*********') - # print(x) - # print('--') - # print(vlans[x]) - # print('*********') - output.write(filename.replace(".txt", "\n")) # 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 continue - # Other catchs - -# 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 + ## Write normal VLAN output try: ipv4 = searchList("ip address", vlans[port]).replace("\n", "").split(" ") 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): output = open("Addressing.csv", "w+") 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")) # Write the ports out to csv @@ -107,20 +146,131 @@ def generateAddressCSV(filenamesList): ipv4 = searchList("ip address", interfaces[port]).replace("\n", "").split(" ") ipv6 = searchList("ipv6 address", interfaces[port]).split(" ")[3].replace("\n", "") 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: - 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() + +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 # Sorted by device type just incase RouterConfigs = ['configs/R1.txt','configs/R2.txt','configs/R3.txt'] SwitchConfigs = ['configs/DLS1.txt', 'configs/DLS2.txt', 'configs/ALS1.txt'] -# MasterList -AllDevices = RouterConfigs + SwitchConfigs +AllDevices = RouterConfigs + SwitchConfigs # MasterList -# Output Addressing Table -# generateAddressCSV(AllDevices) +## Output Addressing Table +generateAddressCSV(AllDevices) -# Output Vlan Table -generateVlanCSV(SwitchConfigs) \ No newline at end of file +## Output Vlan Table +generateVlanCSV(SwitchConfigs) + +## Output BGP Table +generateBGPcsv(RouterConfigs) + +## Output OSPF Table +generateOSPFcsv(AllDevices) + +## Output EIGRP Table +# Seems kinda just basicy \ No newline at end of file