diff --git a/dest.txt b/dest.txt index e085b0b6b2bf79df8771ff7ef0c26d3469b3832e..ecf4fe4e64ef3f88b3ebbd64b952f06ff10608a6 100644 --- a/dest.txt +++ b/dest.txt @@ -1 +1 @@ -192.168.6.1 \ No newline at end of file +192.168.6.2 \ No newline at end of file diff --git a/host.txt b/host.txt index a8a2de608946ec30ce71607c492a57d7a100d49c..5f6b3977c183d4c3c219e7faeb6bb656da265a87 100644 --- a/host.txt +++ b/host.txt @@ -1 +1 @@ -R5 \ No newline at end of file +router5 \ No newline at end of file diff --git a/inventory/hosts.yaml b/inventory/hosts.yaml index e14cc74064a44786f6b2e580037bf8be7de52c0f..51e6c8abeb75fbc4d6e8a7d056a51d88891b4eee 100644 --- a/inventory/hosts.yaml +++ b/inventory/hosts.yaml @@ -1,9 +1,9 @@ [routers] -R1 -R2 -R3 -R4 -R5 +router1 ansible_host=10.10.1.2 +router2 ansible_host=10.10.1.3 +router3 ansible_host=10.10.1.4 +router4 ansible_host=10.10.1.5 +router5 ansible_host=10.10.1.6 [routers:vars] ansible_network_os=cisco.ios.ios diff --git a/networkxtest.py b/networkxtest.py index bf0b1b38f842cb15a1364fdf6e909829f6dc6503..0793be0b888ef95a99cd91b674f59937aca4d8dc 100644 --- a/networkxtest.py +++ b/networkxtest.py @@ -1,6 +1,7 @@ import networkx as nx import matplotlib.pyplot as plt import os as os +import ipaddress class Host: ips = list() @@ -37,6 +38,8 @@ def read(): newitem = Host() + os.system('ansible-playbook playbooks/get_informations.yaml -i inventory/hosts.yaml --ask-pass') + routersNumber = int(input("Adja meg hany router van a halozatban (szammal): ")) searchedNetwork = input("Adja meg a keresett halozatot (maszk nelkul): ") @@ -45,6 +48,7 @@ def read(): sourceRouter = input("Adja meg a kiindulo halozatot (maszk nelkul): ") + for x in range(1, routersNumber + 1): newitem = Host() #reconstruct new item to empty item @@ -58,29 +62,33 @@ def read(): os.system('echo "$(cat ~/onlab/router' + str(x) + '/router' + str(x) + '_routes.txt | grep "^L " | cut -d\' \' -f9 | cut -d\'/\' -f1)" >> ~/onlab/router' + str(x) + '/router' + str(x) + '_locales.txt') with open('./router' + str(x) + '/router' + str(x) + '_locales.txt', 'r') as file_2: for line in file_2.readlines(): - line = line.replace('\n', '') - newitem.ips.append(line) + if line.startswith("10.") == False: + line = line.replace('\n', '') + newitem.ips.append(line) os.system('echo "$(cat ~/onlab/router' + str(x) + '/router' + str(x) + '_routes.txt | grep "^C " | cut -d\' \' -f9 | cut -d\'/\' -f2)" >> ~/onlab/router' + str(x) + '/router' + str(x) + '_masks.txt') with open('./router' + str(x) + '/router' + str(x) + '_masks.txt', 'r') as file_3: for line in file_3.readlines(): - line = line.replace('\n', '') - newitem.masks.append(line) + if line.startswith("10.") == False: + line = line.replace('\n', '') + newitem.masks.append(line) os.system('echo "$(cat ~/onlab/router' + str(x) + '/router' + str(x) + '_routes.txt | grep "^C " | cut -d\' \' -f9 | cut -d\'/\' -f1)" >> ~/onlab/router' + str(x) + '/router' + str(x) + '_networks.txt') with open('./router' + str(x) + '/router' + str(x) + '_networks.txt', 'r') as file_4: for line in file_4.readlines(): - line = line.replace('\n', '') - newitem.networks.append(line) + if line.startswith("10.") == False: + line = line.replace('\n', '') + newitem.networks.append(line) - os.system('echo "$(cat ~/onlab/router' + str(x) + '/router' + str(x) + '_routes.txt | grep "^S " | cut -d\' \' -f5)" >> ~/onlab/router' + str(x) + '/router' + str(x) + '_sroutes.txt') + os.system('echo "$(cat ~/onlab/router' + str(x) + '/router' + str(x) + '_routes.txt | grep "^S " | cut -d\' \' -f6)" >> ~/onlab/router' + str(x) + '/router' + str(x) + '_sroutes.txt') with open('./router' + str(x) + '/router' + str(x) + '_sroutes.txt', 'r') as file_5: for line in file_5.readlines(): - line = line.replace('\n', '') - if line != '': - x = line.split('/') - newitem.sroutes.append(x[0]) - newitem.smasks.append(x[1]) + if line.startswith("10.") == False: + line = line.replace('\n', '') + if line != '': + x = line.split('/') + newitem.sroutes.append(x[0]) + newitem.smasks.append(x[1]) hosts.append(newitem) @@ -116,21 +124,18 @@ def findpath(): pathlist.append(pathelements) def checkroutings(): - + elozo = getelement(pathlist[0][0]) for i in pathlist: for j in i: - elozo = getelement(j) for x in hosts: if j == x.name: for pindex, p in enumerate(x.networks): if searchedNetwork == p: - #print(p) if searchedMask != x.masks[pindex]: - print(x.smasks[pindex]) - p = open("host.txt", "w") p.write(x.name) f = open("repairmask.txt", "w") + f.write(searchedMask) g = open("repairip.txt", "w") g.write(searchedNetwork) @@ -142,14 +147,12 @@ def checkroutings(): #print(elozo.ips[index]) for pindex, p in enumerate(x.sroutes): if searchedNetwork == p: - #print("das") if searchedMask != x.smasks[pindex]: - print(x.smasks[pindex]) - print(j) p = open("host.txt", "w") p.write(x.name) f = open("repairmask.txt", "w") - f.write(searchedMask) + ip4 = ipaddress.IPv4Network((0, searchedMask)) + f.write(str(ip4.netmask)) g = open("repairip.txt", "w") g.write(searchedNetwork) for k in x.networks: @@ -158,6 +161,7 @@ def checkroutings(): h = open("dest.txt", "w") h.write(elozo.ips[index]) #print(elozo.ips[index]) + print(elozo.name) elozo = getelement(j) def getelement(element): @@ -166,7 +170,7 @@ def getelement(element): return i def repairtables(): - #os.system('ansible-playbook playbooks/repair_routing.yaml -i inventory/hosts.yaml') + os.system('ansible-playbook playbooks/repair_routing.yaml -i inventory/hosts.yaml --ask-pass') print("routing javitva") def draw(): diff --git a/playbooks/asd.yaml b/playbooks/asd.yaml index a9e903bd832858cf6aabbfbe019f4e174e09326b..9ae3f605816c5fc58bdacbb4ca335791dccd13ca 100644 --- a/playbooks/asd.yaml +++ b/playbooks/asd.yaml @@ -1,6 +1,6 @@ --- - name: Get informations - hosts: routers + hosts: R1 gather_facts: false connection: network_cli tasks: diff --git a/playbooks/get_informations.yaml b/playbooks/get_informations.yaml index 462933e30b8844d0447238e86cbce8a6f9cdd30d..af542c4f10dee8c12f8098e6a32a7306caff092a 100644 --- a/playbooks/get_informations.yaml +++ b/playbooks/get_informations.yaml @@ -8,11 +8,11 @@ cisco.ios.ios_command: commands: - show run | i hostname - register: hostname + register: hostname - name: Create dir ansible.builtin.file: - path: "{{ ansible_env.HOME }}/onlab/{{ inventory_hostname }}" + path: ~/onlab/{{ inventory_hostname }} state: directory diff --git a/playbooks/repair_routing.yaml b/playbooks/repair_routing.yaml index 8c4c8dbeaf84b149a297f37dabe128ae434710e4..2dc19c066e3b75b28a2ac8cc1d54b017d87b54c9 100644 --- a/playbooks/repair_routing.yaml +++ b/playbooks/repair_routing.yaml @@ -1,6 +1,6 @@ --- - name: Repair routing mask - hosts: {{ lookup('file', 'host.txt') }} + hosts: "{{ lookup('file', '~/onlab/host.txt') }}" gather_facts: false connection: network_cli tasks: @@ -8,4 +8,4 @@ cisco.ios.ios_command: commands: - configure terminal - - ip route 10.10.20.176 {{ lookup('file', 'hely' ) }} 10.10.20.170 + - ip route {{ lookup('file', '~/onlab/repairip.txt') }} {{ lookup('file', '~/onlab/repairmask.txt' ) }} {{ lookup('file', '~/onlab/dest.txt') }} diff --git a/repairmask.txt b/repairmask.txt index cabf43b5ddf813cbe89697372a21373f14921884..5a279b41f09b109350b10ff43266801dfdd48ad8 100644 --- a/repairmask.txt +++ b/repairmask.txt @@ -1 +1 @@ -24 \ No newline at end of file +255.255.255.0 \ No newline at end of file diff --git a/router1/router1_hostname.txt b/router1/router1_hostname.txt index 3c98be3bbe46435be332640d422b96148628a693..fbd0363f730a55dca755f9b1cf7f5e306db8db6b 100644 --- a/router1/router1_hostname.txt +++ b/router1/router1_hostname.txt @@ -1 +1 @@ -hostname R1 \ No newline at end of file +hostname router1 \ No newline at end of file diff --git a/router1/router1_routes.txt b/router1/router1_routes.txt index 70c742579a10814d9db5e0d46da852776783decc..07f3b2feecc17bc3686eb6e4b2edfac696654944 100644 --- a/router1/router1_routes.txt +++ b/router1/router1_routes.txt @@ -1,18 +1,21 @@ Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP - D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 - E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP - i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area - * - candidate default, U - per-user static route, o - ODR - P - periodic downloaded static route + E1 - OSPF external type 1, E2 - OSPF external type 2 + i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 + ia - IS-IS inter area, * - candidate default, U - per-user static route + o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP + a - application route + + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set - 192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks -C 192.168.1.0/24 is directly connected, GigabitEthernet0/0/0 -L 192.168.1.1/32 is directly connected, GigabitEthernet0/0/0 -S 192.168.2.0/24 [1/0] via 192.168.1.2 - 192.168.5.0/24 is variably subnetted, 2 subnets, 2 masks -C 192.168.5.0/24 is directly connected, GigabitEthernet0/0/1 -L 192.168.5.1/32 is directly connected, GigabitEthernet0/0/1 - \ No newline at end of file + 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks +C 10.10.1.0/24 is directly connected, GigabitEthernet2/0/47 +L 10.10.1.2/32 is directly connected, GigabitEthernet2/0/47 + 192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.1.0/24 is directly connected, GigabitEthernet2/0/1 +L 192.168.1.1/32 is directly connected, GigabitEthernet2/0/1 + 192.168.5.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.5.0/24 is directly connected, GigabitEthernet2/0/3 +L 192.168.5.1/32 is directly connected, GigabitEthernet2/0/3 \ No newline at end of file diff --git a/router2/router2_hostname.txt b/router2/router2_hostname.txt index 5cb0be33a5a4403355a36867f128fe5cd355ee16..f008ac1f58a1d981a9eb1e4dabe231ab79e9fa4d 100644 --- a/router2/router2_hostname.txt +++ b/router2/router2_hostname.txt @@ -1 +1 @@ -hostname R2 \ No newline at end of file +hostname router2 \ No newline at end of file diff --git a/router2/router2_routes.txt b/router2/router2_routes.txt index 2e232b9305d2b629813d5a0be4511c66696f2120..5375cfa275d9d4153136e560d79212270929c4fe 100644 --- a/router2/router2_routes.txt +++ b/router2/router2_routes.txt @@ -1,17 +1,21 @@ Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP - D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 - E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP - i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area - * - candidate default, U - per-user static route, o - ODR - P - periodic downloaded static route + E1 - OSPF external type 1, E2 - OSPF external type 2 + i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 + ia - IS-IS inter area, * - candidate default, U - per-user static route + o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP + a - application route + + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set - 192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks -C 192.168.1.0/24 is directly connected, GigabitEthernet0/0/0 -L 192.168.1.2/32 is directly connected, GigabitEthernet0/0/0 - 192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks -C 192.168.2.0/24 is directly connected, GigabitEthernet0/0/1 -L 192.168.2.2/32 is directly connected, GigabitEthernet0/0/1 -S 192.168.3.0/24 [1/0] via 192.168.2.1 \ No newline at end of file + 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks +C 10.10.1.0/24 is directly connected, GigabitEthernet3/0/46 +L 10.10.1.3/32 is directly connected, GigabitEthernet3/0/46 + 192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.1.0/24 is directly connected, GigabitEthernet3/0/1 +L 192.168.1.2/32 is directly connected, GigabitEthernet3/0/1 + 192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.2.0/24 is directly connected, GigabitEthernet3/0/3 +L 192.168.2.2/32 is directly connected, GigabitEthernet3/0/3 \ No newline at end of file diff --git a/router3/router3_hostname.txt b/router3/router3_hostname.txt index 654489221b7c3088f8587bf6d8f9e14ea21dfd9f..368097a76183c2d73bf354905cc1ca3d5f4503bf 100644 --- a/router3/router3_hostname.txt +++ b/router3/router3_hostname.txt @@ -1 +1 @@ -hostname R3 \ No newline at end of file +hostname router3 \ No newline at end of file diff --git a/router3/router3_routes.txt b/router3/router3_routes.txt index e7b73c4292ff75dd2bb4ab9c1e95a359a281ed23..da6b15cc50de0fef91269c772d03347f5c78e0ff 100644 --- a/router3/router3_routes.txt +++ b/router3/router3_routes.txt @@ -1,16 +1,21 @@ Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP - D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 - E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP - i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area - * - candidate default, U - per-user static route, o - ODR - P - periodic downloaded static route + E1 - OSPF external type 1, E2 - OSPF external type 2 + i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 + ia - IS-IS inter area, * - candidate default, U - per-user static route + o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP + a - application route + + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set - 192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks -C 192.168.2.0/24 is directly connected, GigabitEthernet0/0/1 -L 192.168.2.1/32 is directly connected, GigabitEthernet0/0/1 - 192.168.3.0/24 is variably subnetted, 2 subnets, 2 masks -C 192.168.3.0/24 is directly connected, Loopback0 -L 192.168.3.1/32 is directly connected, Loopback0 \ No newline at end of file + 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks +C 10.10.1.0/24 is directly connected, GigabitEthernet3/0/45 +L 10.10.1.4/32 is directly connected, GigabitEthernet3/0/45 + 192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.2.0/24 is directly connected, GigabitEthernet3/0/3 +L 192.168.2.1/32 is directly connected, GigabitEthernet3/0/3 + 192.168.3.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.3.0/24 is directly connected, GigabitEthernet3/0/1 +L 192.168.3.1/32 is directly connected, GigabitEthernet3/0/1 \ No newline at end of file diff --git a/router4/router4_hostname.txt b/router4/router4_hostname.txt index 15f938521e9dee092cc9483f3790a4d20cd9d4ce..d26a06152fdda0ec180274f6a6cfe4edecf7c4a0 100644 --- a/router4/router4_hostname.txt +++ b/router4/router4_hostname.txt @@ -1 +1 @@ -hostname R4 \ No newline at end of file +hostname router4 \ No newline at end of file diff --git a/router4/router4_routes.txt b/router4/router4_routes.txt index c9a9cac47ddd3ef113f13e7d832042d49415fdb5..9dadd59d76755ebe323ececb0987a9c64ff44d88 100644 --- a/router4/router4_routes.txt +++ b/router4/router4_routes.txt @@ -1,19 +1,24 @@ Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP - D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 - E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP - i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area - * - candidate default, U - per-user static route, o - ODR - P - periodic downloaded static route + E1 - OSPF external type 1, E2 - OSPF external type 2 + i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 + ia - IS-IS inter area, * - candidate default, U - per-user static route + o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP + a - application route + + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set - 192.168.3.0/24 is variably subnetted, 2 subnets, 2 masks -C 192.168.3.0/24 is directly connected, GigabitEthernet0/0/0 -L 192.168.3.2/32 is directly connected, GigabitEthernet0/0/0 - 192.168.5.0/24 is variably subnetted, 2 subnets, 2 masks -C 192.168.5.0/24 is directly connected, GigabitEthernet0/0/1 -L 192.168.5.2/32 is directly connected, GigabitEthernet0/0/1 -C 192.168.6.0/24 is directly connected, GigabitEthernet0/0/1 -L 192.168.6.2/32 is directly connected, GigabitEthernet0/0/1 -S 192.168.2.0/24 \ No newline at end of file + 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks +C 10.10.1.0/24 is directly connected, GigabitEthernet5/0/44 +L 10.10.1.5/32 is directly connected, GigabitEthernet5/0/44 + 192.168.3.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.3.0/24 is directly connected, GigabitEthernet5/0/2 +L 192.168.3.2/32 is directly connected, GigabitEthernet5/0/2 + 192.168.5.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.5.0/24 is directly connected, GigabitEthernet5/0/4 +L 192.168.5.2/32 is directly connected, GigabitEthernet5/0/4 + 192.168.6.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.6.0/24 is directly connected, GigabitEthernet5/0/1 +L 192.168.6.2/32 is directly connected, GigabitEthernet5/0/1 \ No newline at end of file diff --git a/router5/router5_hostname.txt b/router5/router5_hostname.txt index 5f7d3b2559145e297df0f254ef658efd84fa85ee..5e1fa2596a7cb34f34a28787eb33d472cb007691 100644 --- a/router5/router5_hostname.txt +++ b/router5/router5_hostname.txt @@ -1 +1 @@ -hostname R5 \ No newline at end of file +hostname router5 \ No newline at end of file diff --git a/router5/router5_routes.txt b/router5/router5_routes.txt index 27d21eceb9d6c3d16ca7a4e3ee95974509619eb9..8f03e5d5ec78eafb974c2090a9a9e75e57c73c52 100644 --- a/router5/router5_routes.txt +++ b/router5/router5_routes.txt @@ -1,16 +1,19 @@ Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP - D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 - E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP - i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area - * - candidate default, U - per-user static route, o - ODR - P - periodic downloaded static route + E1 - OSPF external type 1, E2 - OSPF external type 2 + i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 + ia - IS-IS inter area, * - candidate default, U - per-user static route + o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP + a - application route + + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set - 192.168.4.0/24 is variably subnetted, 2 subnets, 2 masks -C 192.168.4.0/24 is directly connected, GigabitEthernet0/0/1 -L 192.168.4.2/32 is directly connected, GigabitEthernet0/0/1 -C 192.168.6.0/24 is directly connected, GigabitEthernet0/0/1 -L 192.168.6.1/32 is directly connected, GigabitEthernet0/0/1 -S 192.168.2.0/23 \ No newline at end of file + 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks +C 10.10.1.0/24 is directly connected, GigabitEthernet1/0/43 +L 10.10.1.6/32 is directly connected, GigabitEthernet1/0/43 +S 192.168.2.0/23 [1/0] via 192.168.6.2 + 192.168.6.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.6.0/24 is directly connected, GigabitEthernet1/0/1 +L 192.168.6.1/32 is directly connected, GigabitEthernet1/0/1 \ No newline at end of file