-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathkill_daemon.py
More file actions
42 lines (35 loc) · 935 Bytes
/
kill_daemon.py
File metadata and controls
42 lines (35 loc) · 935 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
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
import asyncio
import sys
from contextlib import asynccontextmanager
COMMAND_PORT = 9048
KILL_CMD = b'\x03'
RESPONSE_OK = 0
RESPONSE_ERROR = 255
@asynccontextmanager
async def open_connection(host: str, port: int):
while True:
try:
reader, writer = await asyncio.open_connection(host, port)
except OSError:
await asyncio.sleep(1)
continue
try:
yield reader, writer
break
finally:
await writer.drain()
writer.close()
async def kill(host: str):
async with open_connection(host, COMMAND_PORT) as (_, _):
pass
if __name__ == '__main__':
if len(sys.argv) > 2:
print(f'usage: {__file__} ps5ip')
sys.exit()
if len(sys.argv) == 2:
try:
asyncio.run(kill(sys.argv[1]))
except KeyboardInterrupt:
pass
sys.exit()