Monthly Archive: July 2020

TextFSM

pip list pip install txtfsm pip install colorama Install the template for NTC git clone https://github.com/networktocode/ntc-templates export NET_TEXTFSM=/path/to/ntc-templates/templates/ #ConnectHandler from netmiko import Netmiko from getpass import getpass password = ‘cisco’ devices = {‘host’: ‘100.96.0.18’, ‘username’: ‘ntc’, ‘password’: ‘ntc123’, ‘dev> net_conn…
Read more

Show Commands

#ConnectHandler from pprint import pprint from netmiko import Netmiko from getpass import getpass password = getpass() devices = {‘host’: ‘100.96.0.18’, ‘username’: ‘ntc’, ‘password’: ‘ntc123’, ‘device_type’: ‘cisco_xe’, ‘secret’: password} net_conn = Netmiko(**devices) net_conn.enable() output = net_conn.send_command(“show arp”) print(output) with open(“show_arp.txt”, “w”)…
Read more

Basics

Netmiko is a multi-vendor library base on Paramiko Base Config : #ConnectHandler from pprint import pprint from netmiko import Netmiko from getpass import getpass import re net_conn = Netmiko(host=’100.96.0.18′, username=’ntc’, password=getpass(), device_type=’cisco_xe’) if you use an invalid device type it…
Read more

Classes

Function gives you one level of usability and Classes with methods give you a second level of usability. When you passing the same information more then once for the same thing you can then use Classes instead of repetitive same function. In…
Read more

Functions

Creating a function : def function_name(): ….action function_name()  <— calling the function function_name  <— referencing the function def function_ip(ip): ….print(“My ip is:{}”.format(ip)) or print(f’My ip is :{ip}’) ….return function_ip(‘10.1.1.1′) def function_ip(ip, mask, gtw): ….print(“My ip is:{} mask is : {}…
Read more

Regular Expressions

Summary : http://www.patrickdenis.biz/blog/regular-expressions-special-characters-and-patterns/ . Matches any single character, including white space. * Matches 0 or more sequences of the pattern. + Matches 1 or more sequences of the pattern. ? Matches 0 or 1 occurrences of the pattern. ^ Matches the beginning of…
Read more

Set

Set are like Dictionary but without key value pair, there are just element, if you convert a list to a a set it will remove all duplicate. ipv4 = [‘10.10.10.1’, ‘10.10.10.1’, ‘10.10.10.4, ‘10.10.10.3, ‘10.10.10.3, ‘10.10.10.2, ‘10.10.10.2] set(ipv4) {‘10.10.10.1’, ‘10.10.10.4, ‘10.10.10.3…
Read more

Dictionary Methods

device = {} device[‘ip_addr’] = ‘10.10.10.1’ print(device) {‘ip_addr’: ‘10.10.10.1’} dir(device) will list all method available To loop over a dictionary you can do it by key or key value or both : for key in device: ….print(key) for value in…
Read more