import socket import hmac import hashlib import time host = '192.168.56.1' port = 8888 secretKey = 'j344rfdas' s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) def create_packet(klient_id, even_id, request): timest = (int(time.time())) packet = "{}.{}.{}.{}.{}".format(klient_id, even_id, timest, request, bytes.decode (hashpacket("{}.{}.{}.{}".format(klient_id, even_id, timest, request)))) global requ requ = "{}.{}.{}.{}".format(klient_id, even_id, timest, request) return packet def hashpacket(packet): bytes = str.encode(packet) key = str.encode(secretKey) print(key) print(bytes) hashedpacket = ( hmac.HMAC(key, bytes,hashlib.sha256)) global origkey origkey = hashedpacket.hexdigest() return str.encode(hashedpacket.hexdigest()) def saada(pakett): try: s.connect((host, port)) print("Success connecting to ") print(host," on port: ",str(port)) data = str.encode(pakett) print ("sending :", pakett) s.sendall(str.encode(pakett)) tagasi = (s.recv(2048)) print (tagasi) except socket.error as e: print("Cannot connect to ") print(host," on port: ",str(port)) print(e) alfa = (create_packet(123,4,"Close")) print(alfa) saada(alfa)