Computer and IT knowledge - things to know - All
sample:
how to run the script? how to run the command "show client ip" from HPE aruba switches witch ip 192.168.2.100,192.168.2.101?
./runSwitchCommand.py -user admin -switches 192.168.2.100,192.168.2.101 -command "show client ip"
>> after you press enter you are being ask for a password.
==========================================================================
= runSwitchCommand.py
==========================================================================
#!/usr/bin/python3
# Install required library with: pip install paramiko
import argparse
import getpass
import paramiko
def run_ssh_command(host, username, password, command):
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=host, username=username, password=password, timeout=10)
stdin, stdout, stderr = ssh.exec_command(command)
output = stdout.read().decode()
error = stderr.read().decode()
ssh.close()
if output:
print(f"Output from {host}:\n{output}")
if error:
print(f"Error from {host}:\n{error}")
except Exception as e:
print(f"Failed to connect to {host}: {str(e)}")
def main():
parser = argparse.ArgumentParser(description='Run commands on multiple switches via SSH.')
parser.add_argument('-user', required=True, help='Username for SSH login')
parser.add_argument('-switches', required=True, help='Comma-separated list of switch IPs')
parser.add_argument('-command', required=True, help='Command to run on switches')
args = parser.parse_args()
password = getpass.getpass(prompt='Enter password: ')
switches = [ip.strip() for ip in args.switches.split(',')]
for switch in switches:
print(f"\nConnecting to {switch}...")
run_ssh_command(switch, args.user, password, args.command)
if __name__ == "__main__":
main()
computer2know :: thank you for your visit :: have a nice day :: © 2026