-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh_cmd.py
More file actions
31 lines (19 loc) · 731 Bytes
/
ssh_cmd.py
File metadata and controls
31 lines (19 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import paramiko
def ssh_command(ip, port,user, passwd, cmd):
client= paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(ip, port=port, username=user ,password=passwd)
i,stdout, stderr = client.exec_command(cmd)
output = stdout.readlines() + stderr.readlines()
if output:
print('------ OUTPUT ------')
for line in output:
print(line.strip())
if __name__ == "__main__":
import getpass
user = input('Username: ')
password = getpass.getpass()
ip = input('Enter server ip: ')
port = input ('Enter port: ')
cmd= input('Enter command: ')
ssh_command(ip, port, user, password, cmd)