import socketserver import ipaddr import re class Daemon(): def __init__(self, data): self.data = data self.domain_regexp = re.compile("(?!-)[A-Z\d-]{1,63}(? 255: return False if hostname[-1:] == ".": hostname = hostname[:-1] # strip exactly one dot from the right, if present return all(self.domain_regexp.match(x) for x in hostname.split(".")) # TODO def get_help(self): return "This will be the help" # TODO def get_footer(self): return "This will be the footer" # TODO def get_header(self): return "This will be the header" class WhoisHandler(socketserver.BaseRequestHandler): def setup(self): self.daemon = self.server.daemon def handle(self): data = str(self.request.recv(100).strip(), 'utf-8') print('Received: {}'.format(data)) response = self.daemon.get_header() + " \n" response += self.daemon.query(data) response += self.daemon.get_footer() + "\n" self.request.sendall(bytes(response, 'utf-8')) class ClassicServer(socketserver.ThreadingTCPServer): def __init__(self, config, daemon): host = config['Servers']['classic_host'] port = int(config['Servers']['classic_port']) self.daemon = daemon socketserver.ThreadingTCPServer.__init__(self, (host, port), WhoisHandler) class WebServer(socketserver.ThreadingTCPServer): def __init__(self, config, daemon): self.host = config['Servers']['web_host'] self.port = int(config['Servers']['web_port']) self.daemon = daemon socketserver.ThreadingTCPServer.__init__(self, (self.host, self.port), WhoisHandler)