A very quick demo of how Scrapli can connect to a device run “show version”. The output can be printed in the plain text format from the switch itself or from a parsed version in the form of a Python dictionary

Notes
- Need to install Scrapli and Genie
- Genie will come with a lot of the Cisco PyATS libraries.
pip install scrapli
pip install scrapli[genie]- I had issues with older switches and their older cipher algorithms. The solution was to use paramiko as the transport instead of the system using OpenSSH. This can been seenin the Scrapli script example on line 9.
scrapli.exceptions.ScrapliAuthenticationFailed: No matching key exchange found for host, their offer: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1
Scrapli
from scrapli.driver.core import IOSXEDriver, NXOSDriver
switch = {
"host": "172.16.1.101",
"auth_username":"admin",
"auth_password":"Stefan2020",
"auth_strict_key":False,
# "auth_bypass": True,
"transport": "paramiko"
}
cli = IOSXEDriver(**switch)
cli.open()
output = cli.send_command("show version")
print(output.result)
# Genie Parsed Response
genie_parsed_response = output.genie_parse_output()
print("\n")
print(genie_parsed_response)
Scrapli Output
Output has the show version straight from the IOS switch as well as the bottom line which contains the parsed dictionary from the Genie.
Cisco IOS Software, Linux Software (LINUXL2-UPK9-M), Experimental Version 12.2(20100802:165548) [mtimm-mtrosel2iol 102]
Copyright (c) 1986-2010 by Cisco Systems, Inc.
Compiled Mon 02-Aug-10 10:05 by mtimm
ROM: Bootstrap program is Linux
SW1 uptime is 3 days, 22 hours, 21 minutes
System returned to ROM by reload at 0
System image file is "unix:/opt/gns3/images/IOU/i86bi-linux-l2-upk9-12.2.bin"
This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.
A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html
If you require further assistance please contact us by sending email to
export@cisco.com.
Linux Unix (Intel-x86) processor with 204264K bytes of memory.
Processor board ID 2048001
16 Ethernet interfaces
16K bytes of NVRAM.
Configuration register is 0x0
{'version': {'version_short': '12.2', 'platform': 'Linux', 'version': '12.2(20100802:165548)', 'image_id': 'LINUXL2-UPK9-M', 'label': '[mtimm-mtrosel2iol 102]', 'os': 'IOS', 'image_type': 'developer image', 'copyright_years': '1986-2010', 'compiled_date': 'Mon 02-Aug-10 10:05', 'compiled_by': 'mtimm', 'rom': 'Bootstrap program is Linux', 'hostname': 'SW1', 'uptime': '3 days, 22 hours, 21 minutes', 'returned_to_rom_by': 'reload at 0', 'system_image': 'unix:/opt/gns3/images/IOU/i86bi-linux-l2-upk9-12.2.bin', 'chassis_sn': '2048001', 'number_of_intfs': {'Ethernet': '16'}, 'processor_board_flash': '16K', 'curr_config_register': '0x0'}}