-
Notifications
You must be signed in to change notification settings - Fork 4
/
client.py
68 lines (52 loc) · 1.39 KB
/
client.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python3
#
# Copyright (C) 2019 Michele Scuttari, Marina Nikolic
#
# Usage: keylogger.py serial_port_name
# Example: py keylogger.py COM1
import sys, serial
from serial import SerialException
portName = "COM1"
if len(sys.argv) == 1:
print("[WARNING] No serial port specified. Assuming %s" % portName)
else:
portName = sys.argv[1]
# Connect to the board
try:
ser = serial.Serial(port = portName,
baudrate = 115200,
stopbits = serial.STOPBITS_ONE,
parity = serial.PARITY_NONE,
bytesize = serial.EIGHTBITS,
timeout = 1,
rtscts = False,
dsrdtr = False,
xonxoff = False)
except ValueError:
print("[ERROR] Invalid port configuration")
sys.exit(-1)
except SerialException:
print("[ERROR] Can't open port", portName)
sys.exit(-1)
# Wait for the start message
print("Press the USER button on the board to start logging. Press it again to stop.")
message = ""
while (message != "#start"):
message = ser.readline().decode()
message = message.split("\r\n")[0]
# Start logging
print("Listening...\n")
somethingPrinted = False
message = ser.readline().decode()
while (message != "#stop"):
if (len(message) > 0):
print(message)
somethingPrinted |= len(message) > 0;
message = ser.readline().decode()
message = message.split("\r\n")[0]
if (somethingPrinted):
print("\nStopped")
else:
print("Stopped")
# Close the serial connection
ser.close()