diff --git a/.gitignore b/.gitignore index 13248ecc319a7ea165f0f7d972d56f12e50b7633..6dd85d453e25f8b65520f9eae869f1f649f47c08 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -router1/ -router2/ +**/router? .vscode/ diff --git "a/beszamolo/Statikus routing probl\303\251m\303\241k jav\303\255t\303\241sa Ansible-el.odp" "b/beszamolo/Statikus routing probl\303\251m\303\241k jav\303\255t\303\241sa Ansible-el.odp" new file mode 100644 index 0000000000000000000000000000000000000000..9bf4a914b0a1089c2dc8a8bd4778f558586f5c70 Binary files /dev/null and "b/beszamolo/Statikus routing probl\303\251m\303\241k jav\303\255t\303\241sa Ansible-el.odp" differ diff --git "a/beszamolo/Statikus routing probl\303\251m\303\241k jav\303\255t\303\241sa Ansible-el.pdf" "b/beszamolo/Statikus routing probl\303\251m\303\241k jav\303\255t\303\241sa Ansible-el.pdf" new file mode 100644 index 0000000000000000000000000000000000000000..5792c5786af9f8d80e0ce8a3d2b97527e6a0cb5b Binary files /dev/null and "b/beszamolo/Statikus routing probl\303\251m\303\241k jav\303\255t\303\241sa Ansible-el.pdf" differ diff --git "a/beszamolo/Statikus routing probl\303\251m\303\241k jav\303\255t\303\241sa Ansible-el.pptx" "b/beszamolo/Statikus routing probl\303\251m\303\241k jav\303\255t\303\241sa Ansible-el.pptx" new file mode 100644 index 0000000000000000000000000000000000000000..ea7bc42560aded1d129bb29a8327c560662b2c59 Binary files /dev/null and "b/beszamolo/Statikus routing probl\303\251m\303\241k jav\303\255t\303\241sa Ansible-el.pptx" differ diff --git a/int.sh b/int.sh deleted file mode 100755 index abdfea268ca4b4bc9b7dfd2fa884c6f5696cb401..0000000000000000000000000000000000000000 --- a/int.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -cat ./router2/router2_interface.txt | grep "^ Internet" | cut -d' ' -f6 | cut -d'/' -f1 >> ./router2/router2_ip.txt -cat ./router2/router2_interface.txt | grep "^ Internet" | cut -d' ' -f6 | cut -d'/' -f2 >> ./router2/router2_mask.txt diff --git a/inventory/hosts.yaml b/inventory/hosts.yaml index 64313ee2fa07e3f14814312385b0d4d004296d42..a3b6a15b8762ccb5077dc3ee446bcf6d08bf1d0d 100644 --- a/inventory/hosts.yaml +++ b/inventory/hosts.yaml @@ -1,6 +1,7 @@ [routers] router1 int_mask=255.255.255.248 router2 int_ip=10.10.20.101 +router3 [routers:vars] ansible_become=yes diff --git a/networks.txt b/networks.txt deleted file mode 100644 index f282cf03e21eb4c8e759f02aaa30a66be20547ff..0000000000000000000000000000000000000000 --- a/networks.txt +++ /dev/null @@ -1,2 +0,0 @@ -router1 - gi0/1 - 10.10.20.169 -- network: .129-.174 - 255.255.255.248 -router2 - gi0/1 - 10.10.20.177 -- network: .177-.182 diff --git a/networkxtest.py b/networkxtest.py new file mode 100644 index 0000000000000000000000000000000000000000..7cb14d7b299f61c797018cbb6d111d30d79a70e8 --- /dev/null +++ b/networkxtest.py @@ -0,0 +1,71 @@ +import networkx as nx +import matplotlib.pyplot as plt +import os as os + + +class Hosts: + ips = list() + masks = list() + + def _init__(self, name, ips, masks): + self.name = name + self.ips = [] + self.masks = [] + +G = nx.Graph() + +routersNumber = 3 + +hosts = [] + +for x in range(1, routersNumber + 1): + newitem = Hosts() + os.system('echo "$(cat ~/onlab/router' + str(x) + '/router' + str(x) + '_hostname.txt | grep "h" | cut -d\' \' -f2)" >> ~/onlab/router' + str(x) + '/router' + str(x) + '_name.txt') + with open('./router' + str(x) + '/router' + str(x) + '_name.txt','r') as file_1: + for line in file_1.readlines(): + line = line.replace('\n', '') + newitem.name = line + 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(): + #print(line) + 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(): + #print(line) + line = line.replace('\n', '') + newitem.masks.append(line) + hosts.append(newitem) + + for all in hosts: + print(all.name) + for i in all.ips: + print(i) + for i in all.masks: + print(i) + +for all in hosts: + G.add_node(all.name) + G.add_nodes_from([all.name], ips = all.ips) + G.add_nodes_from([all.name], masks = all.masks) + +for all in hosts: + for toall in hosts: + for ina in all.ips: + for inb in toall.ips: + if ina == inb: + G.add_edge(all.name, toall.name) +print(G.nodes.data()) +nx.draw_networkx(G) +plt.show() + +#for x in range(1,routersNumber + 1): + +for x in range(1, routersNumber + 1 ): + os.system('rm ~/onlab/router' + str(x) + '/router' + str(x) + '_locales.txt ~/onlab/router' + str(x) + '/router' + str(x) + '_name.txt ~/onlab/router' + str(x) + '/router' + str(x) + '_masks.txt') + + + + diff --git a/playbooks/get_informations.yaml b/playbooks/get_informations.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0f12bd717c5b6186a0a866e8b74dbe12e7b56f94 --- /dev/null +++ b/playbooks/get_informations.yaml @@ -0,0 +1,30 @@ +--- +- name: Get informations + hosts: routers + gather_facts: false + connection: network_cli + tasks: + - name: Show hostname + cisco.ios.ios_command: + commands: show run | i hostname + register: hostname + + - name: Create dir + ansible.builtin.file: + path: ~/onlab/{{inventory_hostname}} + state: directory + + - name: Print interface config + copy: + content: "{{hostname.stdout[0]}}" + dest: ~/onlab/{{inventory_hostname}}/{{inventory_hostname}}_hostname.txt + + - name: Show routing tables + cisco.ios.ios_command: + commands: show ip route + register: routes + + - name: Print routing tables + copy: + content: "{{routes.stdout[0]}}" + dest: ~/onlab/{{inventory_hostname}}/{{inventory_hostname}}_routes.txt \ No newline at end of file diff --git a/playbooks/get_interfaces.yaml b/playbooks/get_interfaces.yaml deleted file mode 100644 index 2710319ba6b8dc123f5eee47b3a93d6c3035f6b1..0000000000000000000000000000000000000000 --- a/playbooks/get_interfaces.yaml +++ /dev/null @@ -1,15 +0,0 @@ ---- -- name: Get interfaces - hosts: router2 - gather_facts: false - connection: network_cli - tasks: - - name: Show interfaces informations - cisco.ios.ios_command: - commands: show int gi0/1 - register: interface_config - - - name: Print interface config - copy: - content: "{{interface_config.stdout[0]}}" - dest: ~/onlab/{{inventory_hostname}}/{{inventory_hostname}}_interface.txt diff --git a/playbooks/get_routing_tables.yaml b/playbooks/get_routing_tables.yaml deleted file mode 100644 index be39b03943070980ef059ce686c32dc3f22090c5..0000000000000000000000000000000000000000 --- a/playbooks/get_routing_tables.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -- name: Get routing tables - hosts: router1 - gather_facts: false - connection: network_cli - tasks: - - - name: Show static routing table - cisco.ios.ios_command: - commands: show ip static route - register: routing_table - - - name: Print routing table - copy: - content: "{{routing_table.stdout[0]}}" - dest: ~/onlab/{{inventory_hostname}}/{{inventory_hostname}}_routingt.txt diff --git a/router_config b/router_config index 838fe3a75a0451e6cd38fde8d6852ad09362d7e2..02dc8c0d526d2e1bf3100bcd4c72624c13a21a4d 100644 --- a/router_config +++ b/router_config @@ -1,6 +1,6 @@ enable configure terminal -hostname R2 +hostname R1 enable secret cisco ! username bmzsombi secret cisco @@ -17,7 +17,7 @@ vrf definition Mgmt-intf address-family ipv4 interface g0/0 vrf forwarding Mgmt-intf -ip address 10.10.20.101 255.255.255.0 +ip address 10.10.20.100 255.255.255.0 no shutdown exit ip route vrf Mgmt-intf 0.0.0.0 0.0.0.0 10.10.20.254 diff --git a/sort.sh b/sort.sh deleted file mode 100755 index e389884c514e4714840284be584650c00c18d4dd..0000000000000000000000000000000000000000 --- a/sort.sh +++ /dev/null @@ -1,2 +0,0 @@ -cat ./router1/router1_routingt.txt | grep "^M" | cut -d' ' -f3 | cut -d'/' -f1 >> ./router1/router1_ip.txt -cat ./router1/router1_routingt.txt | grep "^M" | cut -d' ' -f3 | cut -d'/' -f2 >> ./router1/router1_mask.txt diff --git a/start.sh b/start.sh deleted file mode 100755 index dbcd98b976916cfc26ffd8d9683a88ce34bb9a8d..0000000000000000000000000000000000000000 --- a/start.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -ansible-playbook ./playbooks/get_interfaces.yaml -i ./inventory/hosts.yaml -k -K -ansible-playbook ./playbooks/get_routing_tables.yaml -i ./inventory/hosts.yaml -k -K -./sort.sh -./int.sh -python3 maskrecover.py -ansible-playbook ./playbooks/repair_routing.yaml -i ./inventory/hosts.yaml -k -K