2to3port #2

Merged
benjamyn merged 12 commits from 2to3port into master 2020-10-10 18:48:33 -04:00
3 changed files with 110 additions and 96 deletions
Showing only changes of commit a09941ccae - Show all commits

View File

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

View File

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

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# __ __ __ __ ______ __ ______
#/\ \ _ \ \ /\ \_\ \ /\ __ \ /\ \ /\ ___\
#\ \ \/ ".\ \\ \ __ \\ \ \/\ \\ \ \\ \___ \
# /\ \ _ \ \ /\ \_\ \ /\ __ \ /\ \ /\ ___\
# \ \ \/ ".\ \\ \ __ \\ \ \/\ \\ \ \\ \___ \
# \ \__/".~\_\\ \_\ \_\\ \_____\\ \_\\/\_____\
# \/_/ \/_/ \/_/\/_/ \/_____/ \/_/ \/_____/
@ -11,11 +11,14 @@ import os
import socket
import re
import logging
import urllib.request, urllib.parse, urllib.error
import urllib.request
import urllib.parse
import urllib.error
from . import flags
#import error
#import flags
# import flags
class Whois(object):
def __init__(self, domain, debug=False):
@ -32,7 +35,7 @@ class Whois(object):
self.tldList = os.listdir(self.tldPath)
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 = {}
@ -40,10 +43,11 @@ class Whois(object):
logging.debug("__init__: Loading tld configuration file...")
_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:
logging.debug("__init__: Settings: %s"%(_settings["server"]))
logging.debug("__init__: Settings: %s" % (_settings["server"]))
self.settings.update(_settings["server"])
else:
logging.debug("__init__: No server settings found")
@ -51,21 +55,27 @@ class Whois(object):
def chooseServer(self):
'''Choose whois server by detecting tld of given domain.'''
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"]
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"
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":
logging.debug("sendHTTPQuery: Connecting to whois server using POST")
logging.debug(
"sendHTTPQuery: Connecting to whois server using POST")
req = urllib.request.Request(whoisServer, param)
else: # GET
logging.debug("sendHTTPQuery: Connecting to whois server using GET")
req = urllib.request.Request((whoisServer.endswith("?") and whoisServer or whoisServer+"?") + param)
logging.debug(
"sendHTTPQuery: Connecting to whois server using GET")
req = urllib.request.Request((whoisServer.endswith(
"?") and whoisServer or whoisServer+"?") + param)
data = urllib.request.urlopen(req).read()
print(data)
@ -82,16 +92,18 @@ class Whois(object):
except:
# 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
try:
msg = self.settings['format'][whoisServer].replace("%DOMAIN%", self.domain) + "\r\n"
msg = self.settings['format'][whoisServer].replace(
"%DOMAIN%", self.domain) + "\r\n"
except:
msg = self.domain + "\r\n"
logging.debug("sendQuery: Sending data.. %s"%(msg))
logging.debug("sendQuery: Sending data.. %s" % (msg))
# print(msg.encode())
s.send(msg.encode('utf-8'))
@ -107,7 +119,7 @@ class Whois(object):
finalResult = result.replace("\r\n", "\n")
logging.debug("sendQuery: result: %s"%(finalResult))
logging.debug("sendQuery: result: %s" % (finalResult))
return finalResult
@ -121,16 +133,17 @@ class Whois(object):
result = self.sendQuery(whoisServer)
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:
whoisServer = redirection[0]
result = self.sendQuery(whoisServer)
redirection = re.findall(self.settings["redirect"], result)
if return_type == flags.RETURN_TYPE_LIST:
return whoisServer, result
else: