-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsafe_demo.py
More file actions
30 lines (26 loc) · 989 Bytes
/
safe_demo.py
File metadata and controls
30 lines (26 loc) · 989 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
# sender_safe_demo.py — synthetic demo sender (no deps)
import json, time, itertools, datetime, sys, urllib.request
HOST = sys.argv[1] if len(sys.argv) > 1 else "192.168.77.129"
PORT = int(sys.argv[2]) if len(sys.argv) > 2 else 5050
URL = f"http://{HOST}:{PORT}/event"
chars = list("HELLO_DEMO_123")
def post(evt):
data = json.dumps(evt).encode("utf-8")
req = urllib.request.Request(URL, data=data,
headers={"Content-Type": "application/json"},
method="POST")
with urllib.request.urlopen(req, timeout=5) as resp:
resp.read()
while True:
try:
for ch in itertools.cycle(chars):
evt = {
"type": "KEY",
"key": ch,
"window": "Notepad.exe",
"ts": datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
}
post(evt)
time.sleep(0.15)
except Exception:
time.sleep(1)