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