Entradas

Mostrando las entradas etiquetadas como napalm

Napalm | Obtener version software de IOS dada una lista de multiples dispositivos

Este script funciona fenomenal si necesitais obtener la version IOS dada una lista de IPs/Hosts de Routers/Switches Cisco IOS de una forma automatizada. Tener en cuenta que necesitaremos un archivo de "hosts"  donde especificaremos las IPs o Hostnames de los routers o switches Cisco a conectarnos.   SCRIPT 1) Archivo de Hosts (marcado en amarillo en el script) 192.168.1.10 192.168.1.20 192.168.1.30 2) Script import napalm import json f = open (" /home/angel/scripts/hosts ") for line in f:     host = line.strip()     driver = napalm.get_network_driver('ios')     device = driver(hostname=host, username='ssh_user', password='ssh_password')     device.open()     getfacts = device.get_facts()     os_version = getfacts["os_version"]     os_version_split = os_version.split(',')[1].lstrip()     os_version_sliced = os_version_split[8:]     print (os_ver...

Python | Crear archivo .csv con datos obtenidos mediante libreria NAPALM

import napalm # Create a hosts file to include all the target IPs/hostnames that will be SSH'd. f = open ("/home/eve/hosts") # Create a .csv file and define all of the columns matching with NAPALM's "get_facts" output. csv_columns=("FQDN;HOSTNAME;MODEL;OS VERSION;SERIAL NUMBER;UPTIME;VENDOR\n") file= open("napalm.csv","w") file.write(csv_columns) # Create a python loop where it perform the following actions: # 1. Create the "host" variable where we will extract each line of code on every iteration using strip() # 2. Define the NAPALM's driver + SSH Username and Password # 3. Connect to each target host (via SSH) using device.open() # 4. Perform NAPAM's "get_facts" on the target host in order to get general data from the Cisco device in an "structured" way. This data is stored as a "Dictionary". # 5. Take each key data (fqdn, hostname, serial_number...) from "g...

Python + NAPALM | Script para mostrar inventario de Hosts con su serial number

ARCHIVO DE HOSTS nano /home/eve/hosts 192.168.1.100 192.168.1.17 SCRIPT import napalm import json f = open ("/home/eve/hosts") for line in f: host = line.strip() driver = napalm.get_network_driver('ios') device = driver(hostname=host, username='cisco', password='cisco') device.open() getfacts = device.get_facts() get_serialnumber = getfacts["serial_number"] print (host + " " + get_serialnumber) device.close() RESULTADO (OUTPUT)  eve@Linux-Desktop:~$ python3 test1_6.py 192.168.1.100         FTX0945W0MY 192.168.1.17         FTX0945W0MY

Python + NAPALM | Imprimir en pantalla el estado de una interfaz de un Router Cisco

Normalmente cuando ejecutamos un script básico usando la libreria NAPALM y con la función "get_interfaces" obtendriamos un output del equivalente al comando "show ip int brief" de una forma más prográmatica como podemos observar a continuación: eve@Linux-Desktop:~$ python3 test1.py {'FastEthernet0/0': {'description': 'Fa0/0-Test',                      'is_enabled': True,                      'is_up': True,                      'last_flapped': -1.0,                      'mac_address': 'C2:02:0F:F7:00:00',               ...

NAPALM | Script para ejecutar selección comandos Cisco despues de input

Descripción del script Paso 0 - Definir SSH Username y SSH password en el script (editar texto marcado en amarillo abajo en el código) Paso 1 - Ejecutamos el script (python3 napalm-script1.py) y nos pedira a que IP queremos conectarnos via SSH Paso 2 - Una vez definida la IP, nos preguntará que comando queremos ejecutar (ARP, BGP o IP) Paso 3 - Nos mostrara el output seleccionado usando las librerias de NAPALM en driver IOS (Ejemplo. get_arp_table seria devolveria un ouput similar al commando "show ip arp"   Codigo (archivo 'napalm-script1.py') import napalm from pprint import pprint as pp ipaddress = input ( 'Enter Target IP: \n ' ) driver = napalm . get_network_driver ( 'ios' ) device = driver ( hostname = ipaddress , username = ' user_ssh ' , password = 'password_ssh ' ) ...

NAPALM | Script básico para obtener información general de un Cisco switch

1- Creación del script  root@angel-pc:/home/angel/scripts/napalm# nano napalm-script1.py import napalm from pprint import pprint as pp driver = napalm.get_network_driver('ios') device = driver(hostname='192.168.1.10', username=' usuario ', password=' contraseña ') device.open() pp(device. get_facts ()) device.close() 2- Ejecución del script root@angel-pc:/home/angel/scripts/napalm# python3 napalm-script1.py  root@angel-pc:/home/angel/scripts/napalm# python3 napalm-script1.py {'fqdn': 'SW1-lab.local',  'hostname': 'SW1',  'interface_list': ['Vlan1',                     'Vlan10',                     'GigabitEthernet0/0',                     'GigabitEthernet1/0/1',    ...