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

Ethical Hacking Techniques: Cracking WPA/WPA2 Wi-Fi Using WPS and Capturing Handshakes

In the realm of cyber security, ethical hacking plays a crucial role in identifying and addressing vulnerabilities. One of the areas where e...