summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaúl Benencia <rbenencia@linti.unlp.edu.ar>2012-08-03 10:22:48 -0300
committerRaúl Benencia <rbenencia@linti.unlp.edu.ar>2012-08-03 10:22:48 -0300
commit06dea192b5c13a3154d6cd4c6103145ab7c449ba (patch)
treeb31a936a3a881397e59d756b96b4e36d3990d617
parent9d13223e971c1bb37b141cb0b0a3a7dd4077f4d8 (diff)
Semi-functional version
-rw-r--r--core.py29
-rw-r--r--examples/networks.xml2
-rw-r--r--pywhoisd.conf2
3 files changed, 22 insertions, 11 deletions
diff --git a/core.py b/core.py
index cdb5343..430bdf2 100644
--- a/core.py
+++ b/core.py
@@ -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
nihil fit ex nihilo