import datetime import socket from utils import mac_address, broadcast_address 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) destination = byte_string[0:6] if byte_string[12:14] == b"\x60\x00" \ and (destination == mac_address or destination == broadcast_address): source = byte_string[6:12] message = byte_string[14:].decode("utf-8").rstrip("\x00") dt_string = datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S") print("----") print("Revcd from {} to {} @{}".format(source, destination, dt_string)) if message == "ZeusWPI is de max!": print("Congratulations, packet received correctly!") else: print("Wrong message, please check that you are sending \"ZeusWPI is de max!\"")