Skip to content
Snippets Groups Projects
Commit e65c444f authored by Barta Máté Zsombor's avatar Barta Máté Zsombor :speech_balloon:
Browse files

Merge branch 'test' into 'main'

work

See merge request bmzsombi/onlab!1
parents 3cc2bde9 7df6c23a
No related branches found
No related tags found
1 merge request!1work
router1/
router2/
**/router?
.vscode/
File added
File added
File added
#!/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
[routers]
router1 int_mask=255.255.255.248
router2 int_ip=10.10.20.101
router3
[routers:vars]
ansible_become=yes
......
router1 - gi0/1 - 10.10.20.169 -- network: .129-.174 - 255.255.255.248
router2 - gi0/1 - 10.10.20.177 -- network: .177-.182
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')
---
- 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
---
- 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
---
- 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
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
......
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
#!/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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment