[ TOC]
Description: Through the study of the first chapter, we have basically mastered the basics of Python for black hat development and programming, let's learn about the scanning, login and identification of services and ports;
#! /usr/bin/env python
# - *- coding:utf-8-*-
# description: Use Python to implement SSH command execution and return the execution result, then use pyinstaller to convert to executable exe
import paramiko
import argparse
if __name__ =='__main__':
parser = argparse.ArgumentParser(description='ssh commands author: wilson ')
parser.add_argument('--ip',action="store",required=True,dest="ip",type=str,help='ip')
parser.add_argument('--user',action="store",required=True,dest="username",type=str,help='username')
parser.add_argument('--pass',action="store",required=True,dest="password",type=str,help='password')
parser.add_argument("--port",action="store",required=False,dest="port",type=int,default='22',help='port')
parser.add_argument("--cmd",action="store",required=False,dest="cmd",type=str,default='w',help='shell command')
args = parser.parse_args()
ip = args.ip
port = args.port
cmd = args.cmd
username = args.username
password = args.password
try:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(ip, port, username=username, password=password, timeout=10)
stdin, stdout, stderr = client.exec_command(cmd)for std in stdout.readlines():
print std,
client.close()
except Exception as e:
print e
pass
Recommended Posts