-
Notifications
You must be signed in to change notification settings - Fork 0
/
caller.py
49 lines (42 loc) · 1.53 KB
/
caller.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import paramiko
def python_cmd(ssh):
command = "cd D:\\Projects\\paramiko-windows\\remote && d: && call D:\\Projects\\paramiko-windows\\env\\Scripts\\activate.bat && python task.py"
stdin, stdout, stderr = ssh.exec_command(command)
ssh.close()
def exe_cmd():
ssh = create_ssh()
command = "cmd /k notepad.exe"
stdin, stdout, stderr = ssh.exec_command(command)
ssh.close()
def wmic_cmd():
ssh = create_ssh()
command = "wmic process get Caption"
# command = "hostname"
# command = 'wmic cpu get LoadPercentage'
# command = "wmic process where name='pycharm64.exe' call terminate"
# command = "wmic service list brief"
# command = "call D:\\Projects\\paramiko-windows\\remote\\wmic.bat"
command = "wmic process where name='pycharm64.exe'"
command = "wmic process where name='notepad.exe'"
stdin, stdout, stderr = ssh.exec_command(command)
stdout.channel.shutdown_write()
std_out = stdout.read().decode('gbk')
std_out = std_out.replace('\n','').replace('\r','')
if len(std_out) == 0:
print("not any output")
std_err = stderr.read().decode('gbk')
print("stdin",stdin)
print("std_out",std_out)
print("std_err",std_err)
ssh.close()
def create_ssh():
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('127.0.0.1', username='test', password='test123')
shell = ssh.invoke_shell()
return ssh
if __name__ == '__main__':
wmic_cmd()
exe_cmd()
wmic_cmd()