cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
463
Views
0
Helpful
1
Replies

How to compare Cisco software versions in Python?

Timothysaunders
Level 1
Level 1

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

1 Reply 1

balaji.bandi
Hall of Fame
Hall of Fame

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

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help