-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh_cmd.py
More file actions
24 lines (20 loc) · 768 Bytes
/
Copy pathssh_cmd.py
File metadata and controls
24 lines (20 loc) · 768 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
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)
_,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 = getpass.getuser()
user = input('Username: ')
password = getpass.getpass()
ip = input('Enter server IP: ') or '192.168.0.106'
port = input('Enter port or <CR>:') or 2222
cmd = input('Enter command or <CR>:') or 'id'
ssh_command(ip,port,user,password,cmd)