How to compare Cisco software versions in Python?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2022 09:08 PM - edited 12-27-2022 07:36 PM
I need to compare software versions for Cisco devices in Python, but unfortunately packaging. Version doesn't support this format when 3rd and 4th indexes are joined by letters. Anyone can help? My Caregiver Connect
- Labels:
-
Cisco Software
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2022 04:44 AM
here is an example :
# more compare.py
import paramiko
# Set the input string to compare against
input_string = "15.7(3)M3"
# Set up a list of devices to connect to
devices = [
{
"hostname": "10.10.9.3",
"username": "cisco",
"password": "cisco"
},
{
"hostname": "10.10.9.102",
"username": "cisco",
"password": "cisco"
}
]
# Connect to each device and compare the show version output
for device in devices:
# Create a new SSH client
client = paramiko.SSHClient()
# Set the missing host key policy to automatically add new keys
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Connect to the device
client.connect(device["hostname"], username=device["username"], password=device["password"])
# Execute the show version command
stdin, stdout, stderr = client.exec_command("show version")
# Read the output of the command
output = stdout.read().decode()
# Compare the output with the input string
if input_string in output:
print(f"{device['hostname']}: {input_string} found in show version output")
else:
print(f"{device['hostname']}: {input_string} not found in show version output")
# Close the SSH connection
client.close()
python3 -tt compare.py
10.10.9.3: 15.7(3)M3 found in show version output
10.10.9.102: 15.7(3)M3 not found in show version output
