forked from x4nth055/pythoncode-tutorials
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute_commands.py
More file actions
Latest commit
34 lines (28 loc) · 698 Bytes
/
Copy pathexecute_commands.py
File metadata and controls
34 lines (28 loc) · 698 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
32
33
34
importparamiko
hostname="192.168.1.101"
username="test"
password="abc123"
commands= [
"pwd",
"id",
"uname -a",
"df -h"
]
# initialize the SSH client
client=paramiko.SSHClient()
# add to known hosts
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client.connect(hostname=hostname, username=username, password=password)
except:
print("[!] Cannot connect to the SSH Server")
exit()
# execute the commands
forcommandincommands:
print("="*50, command, "="*50)
stdin, stdout, stderr=client.exec_command(command)
print(stdout.read().decode())
err=stderr.read().decode()
iferr:
print(err)
client.close()