frame-it/listener.py

29 lines
994 B
Python
Raw Normal View History

2020-01-21 03:27:35 +01:00
import datetime
import socket
2020-01-22 19:50:57 +01:00
from utils import mac_address
2020-01-21 03:27:35 +01:00
if __name__ == "__main__":
print("Starting listener...")
connection = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(3))
while True:
byte_string, addr = connection.recvfrom(65536)
2020-01-22 19:35:00 +01:00
destination = byte_string[0:6]
if byte_string[12:14] == b"\x60\x00" \
2020-01-22 19:50:57 +01:00
and (destination == mac_address or destination == b'\xff\xff\xff\xff\xff\xff'):
2020-01-21 03:27:35 +01:00
2020-01-22 19:35:00 +01:00
source = byte_string[6:12]
message = byte_string[14:].decode("utf-8").rstrip("\x00")
2020-01-21 03:27:35 +01:00
dt_string = datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S")
print("----")
2020-01-22 19:35:00 +01:00
print("Revcd from {} to {} @{}".format(source, destination, dt_string))
2020-01-21 03:27:35 +01:00
2020-01-22 19:35:00 +01:00
if message == "ZeusWPI is de max!":
2020-01-21 03:27:35 +01:00
print("Congratulations, packet received correctly!")
else:
print("Wrong message, please check that you are sending \"ZeusWPI is de max!\"")