diff options
author | Raúl Benencia <rul@kalgan.cc> | 2012-08-03 15:53:33 -0300 |
---|---|---|
committer | Raúl Benencia <rul@kalgan.cc> | 2012-08-03 15:53:33 -0300 |
commit | 9ca5c7e07f1e5ab4a28c042a72a7f9f29b3426c5 (patch) | |
tree | a457b8168fc6c623c97792e474d97b7ff95e50c4 | |
parent | 21ac58f5dabc78a8c7bb56249f5fa0151202e3d0 (diff) |
Search by domain
-rw-r--r-- | core.py | 37 | ||||
-rw-r--r-- | model.py | 27 | ||||
-rw-r--r-- | pywhoisd.conf | 2 |
3 files changed, 51 insertions, 15 deletions
@@ -26,7 +26,16 @@ class Daemon(): """Receive a dictionary and return a string""" result = "" for k, v in values.items(): - result += '{0}: {1}\n'.format(k, v) + if k == 'domains': + result += '\nAssociated domains\n' + for i, dom in enumerate(v): + result += ' {0}\n'.format(dom.name) + elif k == 'admins': + result += '\nAssociated administrator/s\n ' + for i, adm in enumerate(v): + result += ' {0} {1} <{2}>\n'.format(adm.name, adm.surname, adm.email) + else: + result += '{0}: {1}\n'.format(k, v) return result @@ -38,19 +47,21 @@ class Daemon(): for key in networks: for block in networks[key].ip_blocks: if ipaddr.IPAddress(ip) in ipaddr.IPNetwork(block): - result['name'] = networks[key].name - for k in networks[key].data: - result[k] = networks[key].data[k] - - return result + return networks[key].as_dict(self.data) - result['error'] = "Red no encontrada" + result['error'] = "Network not found" return result - # TODO def search_domain(self, domain): - pass - + # Iterate over all network and check its domains + networks = self.data.get_networks() + domains = self.data.get_domains() + for network in networks.values(): + if any(domains[d].name == domain for d in network.domains): + return network.as_dict(self.data) + + return {'error':'Domain not found'} + # TODO def search_person(self, query): @@ -93,9 +104,9 @@ class WhoisHandler(socketserver.BaseRequestHandler): 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" + #response = self.daemon.get_header() + " \n" + response = self.daemon.query(data) + #response += self.daemon.get_footer() + "\n" self.request.sendall(bytes(response, 'utf-8')) @@ -10,6 +10,29 @@ class Network(): self.ip_blocks = [] self.data = {} + def as_dict(self, data): + # Beautify + result = {} + domains = data.get_domains() + persons = data.get_persons() + + result['name'] = self.name + + # Domains + result['domains'] = [] + for d in self.domains: + result['domains'].append(domains[d]) + + # Admins + result['admins'] = [] + for a in self.admins: + result['admins'].append(persons[a]) + + # Networks + result['networks'] = self.ip_blocks + + return result + class Domain(): """A simple domain definition""" @@ -121,6 +144,7 @@ class DataXML(Data): else: person.data[e.tag] = e.text + print("[+] Read person: {0} - {1} - {2}".format(person.name, person.surname, person.email)) self.persons[elem.attrib['id']] = person def add_domain(self, elem): @@ -129,10 +153,11 @@ class DataXML(Data): domain = Domain() for e in elem: if e.tag == 'name': - domain.name == e.text + domain.name = e.text else: domain.data[e.tag] = e.text + print("[+] Read domain: {}".format(domain.name)) self.domains[elem.attrib['id']] = domain def add_network(self, elem): diff --git a/pywhoisd.conf b/pywhoisd.conf index d4523bf..b18da39 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 = 4343 +classic_port = 4344 # Run a web whois server? web = no |