Telnet with different port a cisco device login and show command using python script
Telnet with different port a Cisco device login and show command using python script
from netmiko import ConnectHandler
# Device information
device = {
'device_type': 'cisco_ios_telnet', # Specify Telnet connection
'host': '192.168.1.1', # IP address of the Cisco device
'port': '32914',
'username': 'cisco', # Telnet username
'password': 'cisco', # Telnet password
'secret': 'cisco', # Enable password (if needed)
}
try:
# Establish Telnet connection
net_connect = ConnectHandler(**device)
# Enter enable mode
net_connect.enable()
# Define the commands to be executed
commands = [
'show run',
'show ip interface brief',
'show version',
]
# Execute each command and capture the output
for command in commands:
output = net_connect.send_command(command)
print(output)
# Close the connection
net_connect.disconnect()
except Exception as e:
print(f"An error occurred: {e}")
Comments
Post a Comment