diff options
-rw-r--r-- | core.py | 29 | ||||
-rw-r--r-- | examples/networks.xml | 2 | ||||
-rw-r--r-- | pywhoisd.conf | 2 |
3 files changed, 22 insertions, 11 deletions
@@ -7,16 +7,26 @@ class Daemon(): def query(self, q): if self.is_ip(q): - self.search_ip(q) + result = self.search_ip(q) elif self.is_domain(q): - self.search_domain(q) + result = self.search_domain(q) else: # Try to find a person with the given query person = search_person(q) if person: - return person + result = person else: - return self.get_help() + result = self.get_help() + + return self.format_result(result) + + def format_result(self, values): + """Receive a dictionary and return a string""" + result = "" + for k, v in values.items(): + result += '{0}: {1}\n'.format(k, v) + + return result def search_ip(self, ip): result = {} @@ -70,13 +80,14 @@ class WhoisHandler(socketserver.BaseRequestHandler): self.daemon = self.server.daemon def handle(self): - data = str(self.request.recv(100), 'utf-8')[:-2] + data = str(self.request.recv(100).strip(), 'utf-8') + print('Received: {}'.format(data)) - response = self.daemon.get_header() + "\n" - response += self.daemon.query(data) + "\n" - response += self.daemon.get_footer() + response = self.daemon.get_header() + " \n" + response += self.daemon.query(data) + response += self.daemon.get_footer() + "\n" - self.request.sendall(response) + self.request.sendall(bytes(response, 'utf-8')) class ClassicServer(socketserver.ThreadingTCPServer): def __init__(self, config, daemon): diff --git a/examples/networks.xml b/examples/networks.xml index 7efe017..2394d6d 100644 --- a/examples/networks.xml +++ b/examples/networks.xml @@ -8,7 +8,7 @@ </network> <network id="2"> - <name>Network one</name> + <name>Network two</name> <ip_block>10.11.0.0/24</ip_block> <domain>2</domain> <admin>2</admin> diff --git a/pywhoisd.conf b/pywhoisd.conf index b18da39..d4523bf 100644 --- a/pywhoisd.conf +++ b/pywhoisd.conf @@ -6,7 +6,7 @@ classic = yes # Only makes sense when classic server is enabled classic_host = localhost -classic_port = 4344 +classic_port = 4343 # Run a web whois server? web = no |