From a4fd6b69650af03f8925d89a6e483ea90c997c20 Mon Sep 17 00:00:00 2001 From: bmzsombi <bmzsombi@sch.bme.hu> Date: Sun, 3 Dec 2023 13:49:14 +0100 Subject: [PATCH] eee --- dest.txt | 2 +- host.txt | 2 +- networkxtest.py | 35 ++++++++++++++--------------------- oldmask.txt | 1 + playbooks/delete_routing.yaml | 11 +++++++++++ router5/router5_routes.txt | 2 +- 6 files changed, 29 insertions(+), 24 deletions(-) create mode 100644 oldmask.txt create mode 100644 playbooks/delete_routing.yaml diff --git a/dest.txt b/dest.txt index ecf4fe4..cf06aab 100644 --- a/dest.txt +++ b/dest.txt @@ -1 +1 @@ -192.168.6.2 \ No newline at end of file +192.168.2.2 \ No newline at end of file diff --git a/host.txt b/host.txt index 5f6b397..4e19eec 100644 --- a/host.txt +++ b/host.txt @@ -1 +1 @@ -router5 \ No newline at end of file +router3 \ No newline at end of file diff --git a/networkxtest.py b/networkxtest.py index 0793be0..c971258 100644 --- a/networkxtest.py +++ b/networkxtest.py @@ -38,7 +38,7 @@ def read(): newitem = Host() - os.system('ansible-playbook playbooks/get_informations.yaml -i inventory/hosts.yaml --ask-pass') + #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): ")) @@ -129,22 +129,6 @@ def checkroutings(): for j in i: for x in hosts: if j == x.name: - for pindex, p in enumerate(x.networks): - if searchedNetwork == p: - if searchedMask != x.masks[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) - for k in x.networks: - for index, h in enumerate(elozo.networks): - if h == k: - h = open("dest.txt", "w") - h.write(elozo.ips[index]) - #print(elozo.ips[index]) for pindex, p in enumerate(x.sroutes): if searchedNetwork == p: if searchedMask != x.smasks[pindex]: @@ -160,8 +144,14 @@ def checkroutings(): if h == k: h = open("dest.txt", "w") h.write(elozo.ips[index]) - #print(elozo.ips[index]) - print(elozo.name) + repairtables() + if searchedMask < x.smasks[pindex]: + print(searchedMask + " " + x.smasks[pindex]) + l = open("oldmask.txt", "w") + ipmask = ipaddress.IPv4Network((0, x.smasks[pindex])) + l.write(str(ipmask.netmask)) + delete() + print(elozo.name + " " + j) elozo = getelement(j) def getelement(element): @@ -169,8 +159,12 @@ def getelement(element): if i.name == element: return i +def delete(): + #os.system('ansible-playbook playbooks/delete_routing.yaml -i inventory/hosts.yaml --ask-pass') + print("deleted") + def repairtables(): - os.system('ansible-playbook playbooks/repair_routing.yaml -i inventory/hosts.yaml --ask-pass') + #os.system('ansible-playbook playbooks/repair_routing.yaml -i inventory/hosts.yaml --ask-pass') print("routing javitva") def draw(): @@ -186,7 +180,6 @@ def main(): graphConstruct() findpath() checkroutings() - repairtables() draw() clear() diff --git a/oldmask.txt b/oldmask.txt new file mode 100644 index 0000000..0c14277 --- /dev/null +++ b/oldmask.txt @@ -0,0 +1 @@ +255.255.255.192 \ No newline at end of file diff --git a/playbooks/delete_routing.yaml b/playbooks/delete_routing.yaml new file mode 100644 index 0000000..624696e --- /dev/null +++ b/playbooks/delete_routing.yaml @@ -0,0 +1,11 @@ +--- +- name: Repair routing mask + hosts: "{{ lookup('file', '~/onlab/host.txt') }}" + gather_facts: false + connection: network_cli + tasks: + - name: Mask repair + cisco.ios.ios_command: + commands: + - configure terminal + - ip route {{ lookup('file', '~/onlab/repairip.txt') }} {{ lookup('file', '~/onlab/oldmask.txt' ) }} {{ lookup('file', '~/onlab/dest.txt') }} \ No newline at end of file diff --git a/router5/router5_routes.txt b/router5/router5_routes.txt index 8f03e5d..70658d0 100644 --- a/router5/router5_routes.txt +++ b/router5/router5_routes.txt @@ -13,7 +13,7 @@ Gateway of last resort is not set 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 +S 192.168.2.0/26 [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 -- GitLab