From 01aa58c5d7947e37bc3f0a927c2ed809873122a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Wed, 1 Aug 2012 18:05:04 -0300 Subject: New scheme. Starting port to python 3. It's now or never! --- core.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 core.py (limited to 'core.py') diff --git a/core.py b/core.py new file mode 100644 index 0000000..5ff69bc --- /dev/null +++ b/core.py @@ -0,0 +1,57 @@ +from ipcalc import IP, Network +import socketserver + +class WhoisDaemon(): + def __init__(data): + self.data = data + + def query(q): + if is_ip(q): + self.search_ip(q) + else: + if is_domain(q): + self.search_domain(q) + else: + return self.print_help() + + def search_ip(self, ip): + result = {} + + # Iterate over all IP block elements + for network in self.data.get_networks(): + for block in network.ip_blocks: + if ip in Network(block): + result['name'] = network.name + for key in network.data: + result[key] = network.data[key] + + return result + + result['error'] = "Red no encontrada" + return result + + def search_domain(self): + pass + +class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler): + + def handle(self): + data = self.request.recv(100) + cur_thread = threading.current_thread() + response = self.get_header() + "\n" + self.get_answer(data) + "\n" + self.get_footer() + self.request.sendall(response) + +class WhoisServer(socketserver.TCPServer): + def __init__(self, config): + host = config.get('Servers', 'classic_host') + port = config.get('Servers', 'classic_port') + + TCPServer.__init__(self, (host, port), ThreadedTCPRequestHandler) + + def start(self): + pass + +class WhoisWebServer(socketserver.TCPServer): + def __init__(self, config): + self.host = config.get('Servers', 'web_host') + self.port = config.get('Servers', 'web_host') -- cgit v1.2.3