Thursday, May 30, 2019

Python paramiko.SSHClient() Examples

Python paramiko Example


### RUN INSTRUCTION###PYTHON PROGRAMNAME.PY <HOST_IP> <HOST_PASSWORD> <LINUX_COMMAND>


######################################################################3
import sys, paramiko

if len(sys.argv) < 4:
    print ("args missing")
    sys.exit(1)
hostname = sys.argv[1]
password = sys.argv[2]
command = sys.argv[3]

username = "root"
port = 22

try:
    client = paramiko.SSHClient()
    client.load_system_host_keys()

    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  #  client.set_missing_host_key_policy(paramiko.WarningPolicy())
    client.connect(hostname, port=port, username=username, password=password)
    stdin, stdout, stderr = client.exec_command(command)
    print (stdout.read())
finally:
    client.close()
##########################################################

1 comment:

  1. Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. Facebook bellen nederland

    ReplyDelete

Wireless Security Configuration: Protect Your Network Now!

Introduction: In today’s connected world, wireless networks are as common as smartphones, and they’re often the gateway to our personal, pr...