Parse Cisco show commands using Python: RegEx Parser Part 4/9: Version Hostname Model Parser

Published: 28 March 2021
on channel: NetworkEvolution
2,904
41

#RegexTutorial #ParseConfig #RegexBeginner

Playlist: Learn to Parse Cisco Configuration using Python RegEx:re Tutorial
   • Learn to Parse Cisco Configuration us...  

Playlist: Python Learning for Network Engineers
   • Python learning for Network Engineers...  

Playlist: Learn to Read Data From CSV Using Python
   • Learn to Read Data from CSV (IP/Confi...  

Playlist: Paramiko detailed explanation with Example for Network Engineers
   • Paramiko Tutorial :Part1  How SSH Hos...  

Script
-------
#! /usr/local/Python_envs/Python3/bin/python3
import re

version_pattern = re.compile(r'Cisco .+ Software, Version (\S+)\n')
model_pattern = re.compile(r'cisco (\S+).+bytes of memory\.')
serial_no_pattern = re.compile(r'Processor board ID (\S+)')
uptime_pattern = re.compile(r'(.+) uptime is (.*)')

with open('01_show_version_output.txt', 'r') as file:
output = file.read()

version_match = version_pattern.search(output)
print('IOS Version'.ljust(18)+': '+version_match.group(1))

model_match = model_pattern.search(output)
print('Model '.ljust(18)+': '+model_match.group(1))

serial_no_match = serial_no_pattern.search(output)
print('Serial Number '.ljust(18)+': '+serial_no_match.group(1))

uptime_match = uptime_pattern.search(output)
print('Host Name '.ljust(18)+': '+uptime_match.group(1))
print('Device Uptime '.ljust(18)+': '+uptime_match.group(2))
--------


ssh parser python,paramiko output parser,cisco show command parser,python regex tutorial,parse cisco ssh output regex,network engineers parser logic,cisco parse example,regex compile tutorial,regex serach and match,shoe command parse outupt and read,ssh output read and parse paramiko,sample regex in python,tutorial regex in python,text parsing in python,commad output parsing python example,networking parser using regex example python,pattern defining in regex,regex for beginners


Watch video Parse Cisco show commands using Python: RegEx Parser Part 4/9: Version Hostname Model Parser online, duration hours minute second in high quality that is uploaded to the channel NetworkEvolution 28 March 2021. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 2,904 times and liked it 41 visitors.