Fixed AU and UK

This commit is contained in:
Benjamyn Love 2020-05-19 09:48:54 -04:00
parent 772c0d5779
commit a09941ccae
3 changed files with 110 additions and 96 deletions

View File

@ -1,5 +1,5 @@
server = { server = {
"host": "whois.auda.ltd", "host": "whois.auda.org.au",
"redirect": "\s+Whois Server: (.*)", # Should never apply to .au domains "redirect": "\s+Whois Server: (.*)", # Should never apply to .au domains
} }
@ -17,6 +17,7 @@ parse = {
"EligibilityName": "Eligibility Name:(.+)", "EligibilityName": "Eligibility Name:(.+)",
"EligibilityType": "Eligibility Type:(.+)", "EligibilityType": "Eligibility Type:(.+)",
"EligibilityID": "Eligibility ID:(.+)", "EligibilityID": "Eligibility ID:(.+)",
"RegistrantID": "Registrant ID:(.+)",
"AdminID": "Registrant Contact ID:(.+)", "AdminID": "Registrant Contact ID:(.+)",
"AdminName": "Registrant Contact Name:(.+)", "AdminName": "Registrant Contact Name:(.+)",
"TechName": "Tech Contact Name:(.+)", "TechName": "Tech Contact Name:(.+)",

View File

@ -8,7 +8,7 @@ parse = {
"NotFound": "No match for", "NotFound": "No match for",
"DomainName": "Domain name:\s+(.+|\n)", "DomainName": "Domain name:\s+(.+|\n)",
"Registrar": "Registrar:\s+(.+)", "Registrar": "Registrar:\s+(.+)",
"NameServer": "Name servers:\s+(.+)", "NameServer": "Name servers:\s+(.+?\n\n)",
"Status": "Registration status:\s+(.+)", "Status": "Registration status:\s+(.+)",
"UpdatedDate": "Last updated:\s+(.+)", "UpdatedDate": "Last updated:\s+(.+)",
"CreationDate": "Registered on:\s+(.+)", "CreationDate": "Registered on:\s+(.+)",

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# __ __ __ __ ______ __ ______ # __ __ __ __ ______ __ ______
#/\ \ _ \ \ /\ \_\ \ /\ __ \ /\ \ /\ ___\ # /\ \ _ \ \ /\ \_\ \ /\ __ \ /\ \ /\ ___\
#\ \ \/ ".\ \\ \ __ \\ \ \/\ \\ \ \\ \___ \ # \ \ \/ ".\ \\ \ __ \\ \ \/\ \\ \ \\ \___ \
# \ \__/".~\_\\ \_\ \_\\ \_____\\ \_\\/\_____\ # \ \__/".~\_\\ \_\ \_\\ \_____\\ \_\\/\_____\
# \/_/ \/_/ \/_/\/_/ \/_____/ \/_/ \/_____/ # \/_/ \/_/ \/_/\/_/ \/_____/ \/_/ \/_____/
@ -11,11 +11,14 @@ import os
import socket import socket
import re import re
import logging import logging
import urllib.request, urllib.parse, urllib.error import urllib.request
import urllib.parse
import urllib.error
from . import flags from . import flags
#import error #import error
#import flags # import flags
class Whois(object): class Whois(object):
def __init__(self, domain, debug=False): def __init__(self, domain, debug=False):
@ -32,7 +35,7 @@ class Whois(object):
self.tldList = os.listdir(self.tldPath) self.tldList = os.listdir(self.tldPath)
logging.debug("__init__: Setting initial variables.. self.currPath = %s / self.tldPath = %s / self.tldList = %s" logging.debug("__init__: Setting initial variables.. self.currPath = %s / self.tldPath = %s / self.tldList = %s"
%(self.currPath, self.tldPath, self.tldList)) % (self.currPath, self.tldPath, self.tldList))
self.settings = {} self.settings = {}
@ -40,10 +43,11 @@ class Whois(object):
logging.debug("__init__: Loading tld configuration file...") logging.debug("__init__: Loading tld configuration file...")
_settings = {} _settings = {}
exec(compile(open(os.path.join(self.tldPath, self.tld)).read(), os.path.join(self.tldPath, self.tld), 'exec'), {}, _settings) exec(compile(open(os.path.join(self.tldPath, self.tld)).read(),
os.path.join(self.tldPath, self.tld), 'exec'), {}, _settings)
if "server" in _settings: if "server" in _settings:
logging.debug("__init__: Settings: %s"%(_settings["server"])) logging.debug("__init__: Settings: %s" % (_settings["server"]))
self.settings.update(_settings["server"]) self.settings.update(_settings["server"])
else: else:
logging.debug("__init__: No server settings found") logging.debug("__init__: No server settings found")
@ -51,21 +55,27 @@ class Whois(object):
def chooseServer(self): def chooseServer(self):
'''Choose whois server by detecting tld of given domain.''' '''Choose whois server by detecting tld of given domain.'''
if "host" in self.settings: if "host" in self.settings:
logging.debug("chooseServer: Whois server addr: %s"%(self.settings["host"])) logging.debug("chooseServer: Whois server addr: %s" %
(self.settings["host"]))
return self.settings["host"] return self.settings["host"]
else: else:
logging.debug("chooseServer: Whois server addr: %s"%(self.tld + ".whois-servers.net")) logging.debug("chooseServer: Whois server addr: %s" %
(self.tld + ".whois-servers.net"))
return self.tld + ".whois-servers.net" return self.tld + ".whois-servers.net"
def sendHTTPQuery(self, whoisServer): def sendHTTPQuery(self, whoisServer):
param = urllib.parse.urlencode({self.settings["http-arg"]: self.domain}) param = urllib.parse.urlencode(
{self.settings["http-arg"]: self.domain})
if self.settings.get("http-method").lower() == "post": if self.settings.get("http-method").lower() == "post":
logging.debug("sendHTTPQuery: Connecting to whois server using POST") logging.debug(
"sendHTTPQuery: Connecting to whois server using POST")
req = urllib.request.Request(whoisServer, param) req = urllib.request.Request(whoisServer, param)
else: # GET else: # GET
logging.debug("sendHTTPQuery: Connecting to whois server using GET") logging.debug(
req = urllib.request.Request((whoisServer.endswith("?") and whoisServer or whoisServer+"?") + param) "sendHTTPQuery: Connecting to whois server using GET")
req = urllib.request.Request((whoisServer.endswith(
"?") and whoisServer or whoisServer+"?") + param)
data = urllib.request.urlopen(req).read() data = urllib.request.urlopen(req).read()
print(data) print(data)
@ -82,16 +92,18 @@ class Whois(object):
except: except:
# FIXME: Create a exception class for this # FIXME: Create a exception class for this
logging.error("sendQuery: Error connecting to whois server %s"%(whoisServer)) logging.error(
"sendQuery: Error connecting to whois server %s" % (whoisServer))
return False return False
try: try:
msg = self.settings['format'][whoisServer].replace("%DOMAIN%", self.domain) + "\r\n" msg = self.settings['format'][whoisServer].replace(
"%DOMAIN%", self.domain) + "\r\n"
except: except:
msg = self.domain + "\r\n" msg = self.domain + "\r\n"
logging.debug("sendQuery: Sending data.. %s"%(msg)) logging.debug("sendQuery: Sending data.. %s" % (msg))
# print(msg.encode()) # print(msg.encode())
s.send(msg.encode('utf-8')) s.send(msg.encode('utf-8'))
@ -107,7 +119,7 @@ class Whois(object):
finalResult = result.replace("\r\n", "\n") finalResult = result.replace("\r\n", "\n")
logging.debug("sendQuery: result: %s"%(finalResult)) logging.debug("sendQuery: result: %s" % (finalResult))
return finalResult return finalResult
@ -121,16 +133,17 @@ class Whois(object):
result = self.sendQuery(whoisServer) result = self.sendQuery(whoisServer)
if redirect and "redirect" in self.settings: if redirect and "redirect" in self.settings:
logging.debug("query: Redirection found. Connecting to given server address") logging.debug(
"query: Redirection found. Connecting to given server address")
redirection = re.findall(self.settings["redirect"], result, re.MULTILINE) redirection = re.findall(
self.settings["redirect"], result, re.MULTILINE)
while redirection and len(redirection) >= 1: while redirection and len(redirection) >= 1:
whoisServer = redirection[0] whoisServer = redirection[0]
result = self.sendQuery(whoisServer) result = self.sendQuery(whoisServer)
redirection = re.findall(self.settings["redirect"], result) redirection = re.findall(self.settings["redirect"], result)
if return_type == flags.RETURN_TYPE_LIST: if return_type == flags.RETURN_TYPE_LIST:
return whoisServer, result return whoisServer, result
else: else: