Patrick Denis > Articles by: admin
Author Archive: admin
admin
July 24, 2020
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
admin
July 24, 2020
#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
admin
July 24, 2020
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
admin
July 24, 2020
Make you share code between scripts. Make you able to import a module ( file with a code ) Example : import file_ex ( file_ex.py ) dir(file_ex) then you would be able to use all method and attribute of that…
Read more
admin
July 24, 2020
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
admin
July 24, 2020
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
admin
July 22, 2020
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
admin
July 22, 2020
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
admin
July 22, 2020
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
admin
July 22, 2020
Dictionary are {key: value, key2: value2, etc..} device = {} device[‘ip_addr’] = ‘10.10.10.1’ print(device) {‘ip_addr’: ‘10.10.10.1’}