39 lines
906 B
Python
39 lines
906 B
Python
import paramiko
|
|
|
|
# SSH connection details
|
|
host = "172.31.142.223"
|
|
username = "admin"
|
|
password = "T15462&93016n." # Replace with actual password
|
|
command = "show access-control-config"
|
|
|
|
# Create SSH client
|
|
ssh = paramiko.SSHClient()
|
|
|
|
# Automatically add host key (not secure for production, consider using ssh_keys)
|
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
|
|
try:
|
|
# Connect to the host
|
|
ssh.connect(host, username=username, password=password)
|
|
|
|
# Execute the command
|
|
stdin, stdout, stderr = ssh.exec_command(command)
|
|
|
|
# Read the output
|
|
output = stdout.read().decode()
|
|
error = stderr.read().decode()
|
|
|
|
# Print the output
|
|
print("Command Output:")
|
|
print(output)
|
|
|
|
if error:
|
|
print("Error:")
|
|
print(error)
|
|
|
|
except Exception as e:
|
|
print(f"An error occurred: {str(e)}")
|
|
|
|
finally:
|
|
# Close the connection
|
|
ssh.close()
|