summaryrefslogtreecommitdiff
path: root/core.py
diff options
context:
space:
mode:
authorRaúl Benencia <rbenencia@linti.unlp.edu.ar>2012-08-02 13:58:58 -0300
committerRaúl Benencia <rbenencia@linti.unlp.edu.ar>2012-08-02 13:58:58 -0300
commit10e9272d170f5c634e8ca8f7415fb4ad1454bfe6 (patch)
tree8a41526b84c0586677bdc57fb62ee797efb14552 /core.py
parent9afa33502b67151f36561119b70c765af675c1ca (diff)
Finished port to python3. Untested.
Diffstat (limited to 'core.py')
-rw-r--r--core.py50
1 files changed, 36 insertions, 14 deletions
diff --git a/core.py b/core.py
index 5ff69bc..98284e1 100644
--- a/core.py
+++ b/core.py
@@ -1,18 +1,24 @@
-from ipcalc import IP, Network
import socketserver
+import ipcalc
-class WhoisDaemon():
+class Daemon():
def __init__(data):
self.data = data
def query(q):
- if is_ip(q):
+ if self.is_ip(q):
self.search_ip(q)
+
+ elif self.is_domain(q):
+ self.search_domain(q)
+
else:
- if is_domain(q):
- self.search_domain(q)
+ # Try to find a person with the given query
+ person = search_person(q)
+ if person:
+ return person
else:
- return self.print_help()
+ return self.show_help()
def search_ip(self, ip):
result = {}
@@ -20,7 +26,7 @@ class WhoisDaemon():
# Iterate over all IP block elements
for network in self.data.get_networks():
for block in network.ip_blocks:
- if ip in Network(block):
+ if ip in ipcalc.Network(block):
result['name'] = network.name
for key in network.data:
result[key] = network.data[key]
@@ -30,9 +36,25 @@ class WhoisDaemon():
result['error'] = "Red no encontrada"
return result
- def search_domain(self):
+ # TODO
+ def search_domain(self, domain):
pass
+ def search_person(self, query):
+ pass
+
+ # TODO
+ def is_ip(self, query):
+ pass
+
+ # TODO
+ def is_domain(self, query):
+ pass
+
+ # TODO
+ def show_help():
+ pass
+
class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):
def handle(self):
@@ -41,17 +63,17 @@ class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):
response = self.get_header() + "\n" + self.get_answer(data) + "\n" + self.get_footer()
self.request.sendall(response)
-class WhoisServer(socketserver.TCPServer):
+class ClassicServer(socketserver.TCPServer):
def __init__(self, config):
- host = config.get('Servers', 'classic_host')
- port = config.get('Servers', 'classic_port')
+ host = config['Servers']['classic_host']
+ port = config['Servers']['classic_port']
TCPServer.__init__(self, (host, port), ThreadedTCPRequestHandler)
def start(self):
pass
-class WhoisWebServer(socketserver.TCPServer):
+class WebServer(socketserver.TCPServer):
def __init__(self, config):
- self.host = config.get('Servers', 'web_host')
- self.port = config.get('Servers', 'web_host')
+ self.host = config['Servers']['web_host']
+ self.port = config['Servers']['web_port']
nihil fit ex nihilo