#!/usr/bin/env python3 from socket import * from subprocess import getoutput from time import sleep # Create a socket. This doesn't open a port or anything yet # Parameters: # AF_INET is ipv4, AF_INET6 # SOCK_STREAM means TCP, SOCK_DGRAM would be UDP our_socket = socket(AF_INET, SOCK_STREAM) # Bind is only for servers, not client # clients call connect instead # Still doesn't open it, although we have an address # Double parenthesis = 1 argument which is a tuple our_socket.bind(("0.0.0.0", 5109)) # Actually opens the port # Argument is a queue of connections to accept our_socket.listen(5) while True: client_socket, client_address = our_socket.accept() print("We got a new connection from: ", client_address[0], client_address[1]) key = client_socket.recv(65).decode("utf-8").strip() print("The client sent us: ", key) client_socket.close() current_key = getoutput("echo caterpiller" + getoutput("date +%d%h%m%Y") + " | sha256sum | sed 's/-//g'").strip() print("current_key = ", current_key) if(key == current_key): getoutput("echo " + client_address[0] + " > ip_storage_file") sleep(60 * 60) our_socket.close()