forked from cournape/aio-winrm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
48 lines (37 loc) · 1.22 KB
/
example.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
import asyncio
from aiowinrm import \
run_cmd, \
run_ps, \
run_psrp, \
build_win_rm_url, \
ConnectionOptions, \
AuthEnum
def print_output(res):
std_out, std_err, exit_code = res
if std_out:
print('OUTPUT:\r\n', std_out)
if std_err:
print('ERROR:\r\n', std_err)
async def run_cmd_print(conn_opts, cmd, params=()):
res = await run_cmd(conn_opts, cmd, params)
print_output(res)
async def run_ps_print(conn_opts, script):
res = await run_ps(conn_opts, script)
print_output(res)
async def run_psrp_print(conn_opts, script):
res = await run_psrp(conn_opts, script)
print_output(res)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
connection_options = ConnectionOptions(
winrm_url=build_win_rm_url('1.2.3.4', use_https=True),
auth_method=AuthEnum.Basic, # since we're using https anyway
username='administrator',
password='password',
verify_ssl=False, # if using self signed certificate
loop=loop
)
coro = run_psrp_print(connection_options, "Get-WmiObject Win32_OperatingSystem")
#coro = run_cmd_print(connection_options, "netstat -an")
loop.run_until_complete(coro)
loop.close()