def test_nslookup(self): """ This method test the viability of Lookup().nslookup() """ # Test of the case that the domains is down expected = False PyFunceble.CONFIGURATION["domain"] = "thisdoes-not-workdnfhfep.de" actual = Lookup().nslookup() self.assertEqual(expected, actual) # Test of the case that the domains is invalid expected = False PyFunceble.CONFIGURATION["domain"] = "helloworld-.com" actual = Lookup().nslookup() self.assertEqual(expected, actual) # Test of the case that the domains is up expected = True PyFunceble.CONFIGURATION["domain"] = "google.com" actual = Lookup().nslookup() self.assertEqual(expected, actual) del PyFunceble.CONFIGURATION["domain"]
def test_nslookup_domain_up(self): """ Test of Lookup().nslookup() for the case a domain is up. """ expected = True PyFunceble.INTERN["to_test"] = "google.com" actual = Lookup().nslookup() self.assertEqual(expected, actual) PyFunceble.INTERN["to_test"] = "172.217.22.14" actual = Lookup().nslookup() self.assertEqual(expected, actual) del PyFunceble.INTERN["to_test"]
def test_nslookup_domain_invalid(self): """ Test of Lookup().nslookup() for the case a domain is invalid. """ expected = False PyFunceble.INTERN["to_test"] = "helloworld-.com" actual = Lookup().nslookup() self.assertEqual(expected, actual) del PyFunceble.INTERN["to_test"]
def test_nslookup_domain_down(self): """ Test of Lookup().nslookup() for the case a domain is down or non existant. """ expected = False PyFunceble.INTERN["to_test"] = "thisdoes-not-workdnfhfep.de" actual = Lookup().nslookup() self.assertEqual(expected, actual) del PyFunceble.INTERN["to_test"]
def handle(self): """ Handle the lack of WHOIS. :smile_cat: :return: The strus of the domain after generating the files desired by the user. :rtype: str """ if self.matched_status.lower( ) not in PyFunceble.STATUS["list"]["invalid"]: # The matched status is not in the list of invalid status. # We initiate the source we are going to parse to the Generate class. source = "NSLOOKUP" if Lookup().nslookup(): # We could execute the nslookup logic. # We generate the status files with the up status. Generate(PyFunceble.STATUS["official"]["up"], source).status_file() # We return the up status. return PyFunceble.STATUS["official"]["up"] # We could not execute the nslookup logic. # * We generate the status file with the down status. Generate(PyFunceble.STATUS["official"]["down"], source).status_file() # We return the down status. return PyFunceble.STATUS["official"]["down"] # The matched status is in the list of invalid status. # We generate the status file with the invalid status. Generate(PyFunceble.STATUS["official"]["invalid"], self.invalid_source).status_file() # We return the invalid status. return PyFunceble.STATUS["official"]["invalid"]
def handle(self): """ Handle the lack of WHOIS. :) Returns: str The status of the domains after generating the files. """ source = "NSLOOKUP" if self.matched_status.lower( ) not in PyFunceble.STATUS["list"]["invalid"]: if Lookup().nslookup(): Generate(PyFunceble.STATUS["official"]["up"], source).status_file() return PyFunceble.STATUS["official"]["up"] Generate(PyFunceble.STATUS["official"]["down"], source).status_file() return PyFunceble.STATUS["official"]["down"] Generate(PyFunceble.STATUS["official"]["invalid"], "IANA").status_file() return PyFunceble.STATUS["official"]["invalid"]
def _extract(self): # pragma: no cover """ Extract the expiration date from the whois record. :return: The status of the domain. :rtype: str """ # We try to get the expiration date from the database. expiration_date_from_database = Whois().get_expiration_date() if expiration_date_from_database: # The hash of the current whois record did not changed and the # expiration date from the database is not empty not equal to # None or False. # We generate the files and print the status. # It's an active element! Generate( PyFunceble.STATUS["official"]["up"], "WHOIS", expiration_date_from_database, ).status_file() # We handle und return the official up status. return PyFunceble.STATUS["official"]["up"] # We get the whois record. self.whois_record = Lookup().whois(PyFunceble.INTERN["referer"]) # We list the list of regex which will help us get an unformatted expiration date. to_match = [ r"expire:(.*)", r"expire on:(.*)", r"Expiry Date:(.*)", r"free-date(.*)", r"expires:(.*)", r"Expiration date:(.*)", r"Expiry date:(.*)", r"Expire Date:(.*)", r"renewal date:(.*)", r"Expires:(.*)", r"validity:(.*)", r"Expiration Date :(.*)", r"Expiry :(.*)", r"expires at:(.*)", r"domain_datebilleduntil:(.*)", r"Data de expiração \/ Expiration Date \(dd\/mm\/yyyy\):(.*)", r"Fecha de expiración \(Expiration date\):(.*)", r"\[Expires on\](.*)", r"Record expires on(.*)(\(YYYY-MM-DD\))", r"status: OK-UNTIL(.*)", r"renewal:(.*)", r"expires............:(.*)", r"expire-date:(.*)", r"Exp date:(.*)", r"Valid-date(.*)", r"Expires On:(.*)", r"Fecha de vencimiento:(.*)", r"Expiration:.........(.*)", r"Fecha de Vencimiento:(.*)", r"Registry Expiry Date:(.*)", r"Expires on..............:(.*)", r"Expiration Time:(.*)", r"Expiration Date:(.*)", r"Expired:(.*)", r"Date d'expiration:(.*)", ] if self.whois_record: # The whois record is not empty. if "current_test_data" in PyFunceble.INTERN: # The end-user want more information whith his test. # We update the whois_record index. PyFunceble.INTERN["current_test_data"][ "whois_record"] = self.whois_record for string in to_match: # We loop through the list of regex. # We try tro extract the expiration date from the WHOIS record. expiration_date = Regex(self.whois_record, string, return_data=True, rematch=True, group=0).match() if expiration_date: # The expiration date could be extracted. # We get the extracted expiration date. self.expiration_date = expiration_date[0].strip() # We initate a regex which will help us know if a number # is present into the extracted expiration date. regex_rumbers = r"[0-9]" if Regex(self.expiration_date, regex_rumbers, return_data=False).match(): # The extracted expiration date has a number. # We format the extracted expiration date. self.expiration_date = self._format() if (self.expiration_date and not Regex( self.expiration_date, r"[0-9]{2}\-[a-z]{3}\-2[0-9]{3}", return_data=False, ).match()): # The formatted expiration date does not match our unified format. # We log the problem. Logs().expiration_date(self.expiration_date) # We log the whois record. Logs().whois(self.whois_record) if "current_test_data" in PyFunceble.INTERN: # The end-user want more information whith his test. # We update the expiration_date index. PyFunceble.INTERN["current_test_data"][ "expiration_date"] = self.expiration_date # We generate the files and print the status. # It's an active element! Generate( PyFunceble.STATUS["official"]["up"], "WHOIS", self.expiration_date, ).status_file() # We log the whois record. Logs().whois(self.whois_record) # We save the whois record into the database. Whois(expiration_date=self.expiration_date).add() # We handle und return the official up status. return PyFunceble.STATUS["official"]["up"] # The extracted expiration date does not have a number. # We log the whois record. Logs().whois(self.whois_record) # We handle and return and h the official down status. return Status( PyFunceble.STATUS["official"]["down"]).handle() # The whois record is empty. # We handle and return the official down status. return Status(PyFunceble.STATUS["official"]["down"]).handle()
def handle(cls, status, invalid_source="IANA"): """ Handle the lack of WHOIS and expiration date. :smile_cat: :param matched_status: The status that we have to handle. :type status: str :param invalid_source: The source to set when we handle INVALID element. :type invalid_source: str :return: The strus of the domain after generating the files desired by the user. :rtype: str """ if status.lower() not in PyFunceble.STATUS["list"]["invalid"]: # The matched status is not in the list of invalid status. # We initiate the source we are going to parse to the Generate class. source = "NSLOOKUP" if Lookup().nslookup(): # We could execute the nslookup logic. # We get the status and source after extra rules check. status, source = cls.extra_rules.handle( PyFunceble.STATUS["official"]["up"], source ) # We generate the status files with the up status. Generate(status, source).status_file() # We return the up status. return status, source # We could not execute the nslookup logic. # We get the status and source after extra rules check. status, source = cls.extra_rules.handle( PyFunceble.STATUS["official"]["down"], source ) # We generate the status file with the down status. Generate(status, source).status_file() # We return the down status. return status, source # The matched status is in the list of invalid status. # We get the status and source after extra rules check. status, source = cls.extra_rules.handle( PyFunceble.STATUS["official"]["invalid"], invalid_source ) # We generate the status file with the invalid status. Generate(status, source).status_file() # We return the status. return status, source
def referer(cls, extension): """ Return the referer for the given extension. :pram extension: A string, a valid domain extension. """ manual_server = { "aaa": "whois.nic.aaa", "abb": "whois.nic.abb", "able": "whois.nic.able", "accenture": "whois.nic.accenture", "aetna": "whois.nic.aetna", "aig": "whois.nic.aig", "americanexpress": "whois.nic.americanexpress", "amex": "whois.nic.amex", "amica": "whois.nic.amica", "amsterdam": "whois.nic.amsterdam", "analytics": "whois.nic.analytics", "aramco": "whois.nic.aramco", "athleta": "whois.nic.athleta", "audible": "whois.nic.audible", "author": "whois.nic.author", "aws": "whois.nic.aws", "axa": "whois.nic.axa", "azure": "whois.nic.azure", "baby": "whois.nic.baby", "banamex": "whois.nic.banamex", "bananarepublic": "whois.nic.bananarepublic", "baseball": "whois.nic.baseball", "bharti": "whois.nic.bharti", "bing": "whois.nic.bing", "bloomberg": "whois.nic.bloomberg", "bm": "whois.afilias-srs.net", "book": "whois.nic.book", "booking": "whois.nic.booking", "bot": "whois.nic.bot", "bz": "whois.afilias-grs.net", "buzz": "whois.nic.buzz", "call": "whois.nic.call", "calvinklein": "whois.nic.calvinklein", "caravan": "whois.nic.caravan", "cartier": "whois.nic.cartier", "cbn": "whois.nic.cbn", "cbre": "whois.nic.cbre", "cd": "chois.nic.cd", "chase": "whois.nic.chase", "circle": "whois.nic.circle", "cisco": "whois.nic.cisco", "citadel": "whois.nic.citadel", "citi": "whois.nic.citi", "citic": "whois.nic.citic", "cm": "whois.netcom.cm", "coupon": "whois.nic.coupon", "crown": "whois.nic.crown", "crs": "whois.nic.crs", "deal": "whois.nic.deal", "dealer": "whois.nic.dealer", "dell": "whois.nic.dell", "dhl": "whois.nic.dhl", "discover": "whois.nic.discover", "dnp": "whois.nic.dnp", "duns": "whois.nic.duns", "dupont": "whois.nic.dupont", "earth": "whois.nic.earth", "epost": "whois.nic.epost", "everbank": "whois.nic.everbank", "farmers": "whois.nic.farmers", "fast": "whois.nic.fast", "ferrero": "whois.nic.ferrero", "fire": "whois.nic.fire", "fj": "whois.usp.ac.fj", "flickr": "whois.nic.flickr", "flir": "whois.nic.flir", "food": "whois.nic.food", "ford": "whois.nic.ford", "fox": "whois.nic.fox", "free": "whois.nic.free", "frontier": "whois.nic.frontier", "ftr": "whois.nic.ftr", "ga": "whois.my.ga", "gap": "whois.nic.gap", "gh": "whois.nic.gh", "gmo": "whois.nic.gmo", "got": "whois.nic.got", "grainger": "whois.nic.grainger", "grocery": "whois.nic.grocery", "guardian": "whois.nic.guardian", "gucci": "whois.nic.gucci", "hair": "whois.nic.hair", "hbo": "whois.nic.hbo", "health": "whois.nic.health", "homegoods": "whois.nic.homegoods", "homesense": "whois.nic.homesense", "honeywell": "whois.nic.honeywell", "hoteles": "whois.nic.hoteles", "hotels": "whois.nic.hotels", "hotmail": "whois.nic.hotmail", "hyatt": "whois.nic.hyatt", "hsbc": "whois.nic.hsbc", "hot": "whois.nic.hot", "ieee": "whois.nic.ieee", "imdb": "whois.nic.imdb", "int": "whois.iana.org", "intel": "whois.nic.intel", "intuit": "whois.nic.intuit", "ipirange": "whois.nic.ipiranga", "itau": "whois.nic.itau", "iwc": "whois.nic.iwc", "jetzt": "whois.nic.jetzt", "jlc": "whois.nic.jlc", "jmp": "whois.nic.jmp", "jnj": "whois.nic.jnj", "jot": "whois.nic.jot", "joy": "whois.nic.joy", "jpmorgan": "whois.nic.jpmorgan", "jprs": "whois.nic.jprs", "kinder": "whois.nic.kinder", "kindle": "whois.nic.kindle", "kpmg": "whois.nic.kpmg", "kpn": "whois.nic.kpn", "kred": "whois.nic.kred", "kw": "whois.nic.kw", "lanxess": "whois.nic.lanxess", "lc": "whois2.afilias-grs.net", "lifeinsurance": "whois.nic.lifeinsurance", "like": "whois.nic.like", "lilly": "whois.nic.lilly", "lincoln": "whois.nic.lincoln", "living": "whois.nic.living", "lk": "whois.nic.lk", "loft": "whois.nic.loft", "microsoft": "whois.nic.microsoft", "nagoya": "whois.nic.nagoya", "nyc": "whois.nic.nyc", "ps": "whois.pnina.ps", "ren": "whois.nic.ren", "rw": "whois.ricta.org.rw", "shop": "whois.nic.shop", "sl": "whois.nic.sl", "stream": "whois.nic.stream", "tokyo": "whois.nic.tokyo", "uno": "whois.nic.uno", "za": "whois.registry.net.za", } if extension in manual_server: return manual_server[extension] else: whois_record = Lookup().whois( PyFunceble.CONFIGURATION["iana_whois_server"], "hello." + extension, 10 ) if whois_record: regex_referer = r"(refer:)\s+(.*)" matched = Regex( whois_record, regex_referer, return_data=True, rematch=True ).match() if matched: return matched[1] return None
def __init__(self): # We get the destination of the constructed IANA database. self.destination = (PyFunceble.CURRENT_DIRECTORY + PyFunceble.OUTPUTS["default_files"]["iana"]) if PyFunceble.path.isfile(self.destination): # The destination exist. # We get its content. self.iana_db = Dict().from_json(File(self.destination).read()) else: # The destination does not exist. # We initiate the local variable which will save the content of the database. self.iana_db = {} # We initiate the URL to the IANA Root Zone Database page. self.iana_url = "https://www.iana.org/domains/root/db" # We iniitate an instance of Lookup. self.lookup = Lookup() # We map the list of server which have to be set manually because # they are not present into the IANA Root Zone Database. self.manual_server = { "aaa": "whois.nic.aaa", "abb": "whois.nic.abb", "able": "whois.nic.able", "accenture": "whois.nic.accenture", "aetna": "whois.nic.aetna", "aig": "whois.nic.aig", "americanexpress": "whois.nic.americanexpress", "amex": "whois.nic.amex", "amica": "whois.nic.amica", "amsterdam": "whois.nic.amsterdam", "analytics": "whois.nic.analytics", "aramco": "whois.nic.aramco", "arte": "whois.nic.arte", "as": "whois.nic.as", "athleta": "whois.nic.athleta", "audible": "whois.nic.audible", "author": "whois.nic.author", "aws": "whois.nic.aws", "axa": "whois.nic.axa", "azure": "whois.nic.azure", "baby": "whois.nic.baby", "banamex": "whois.nic.banamex", "bananarepublic": "whois.nic.bananarepublic", "baseball": "whois.nic.baseball", "bharti": "whois.nic.bharti", "bing": "whois.nic.bing", "bloomberg": "whois.nic.bloomberg", "bm": "whois.afilias-srs.net", "book": "whois.nic.book", "booking": "whois.nic.booking", "bot": "whois.nic.bot", "buzz": "whois.nic.buzz", "bz": "whois.afilias-grs.net", "call": "whois.nic.call", "calvinklein": "whois.nic.calvinklein", "caravan": "whois.nic.caravan", "cartier": "whois.nic.cartier", "caseih": "whois.nic.caseih", "cbn": "whois.nic.cbn", "cbre": "whois.nic.cbre", "cd": "chois.nic.cd", "chase": "whois.nic.chase", "circle": "whois.nic.circle", "cisco": "whois.nic.cisco", "citadel": "whois.nic.citadel", "citi": "whois.nic.citi", "citic": "whois.nic.citic", "cm": "whois.netcom.cm", "coupon": "whois.nic.coupon", "crown": "whois.nic.crown", "crs": "whois.nic.crs", "deal": "whois.nic.deal", "dealer": "whois.nic.dealer", "dell": "whois.nic.dell", "dhl": "whois.nic.dhl", "discover": "whois.nic.discover", "dnp": "whois.nic.dnp", "doosan": "whois.nic.doosan", "duns": "whois.nic.duns", "dupont": "whois.nic.dupont", "earth": "whois.nic.earth", "energy": "whois.nic.energy", "epost": "whois.nic.epost", "everbank": "whois.nic.everbank", "farmers": "whois.nic.farmers", "fast": "whois.nic.fast", "ferrero": "whois.nic.ferrero", "fire": "whois.nic.fire", "fj": "whois.usp.ac.fj", "flickr": "whois.nic.flickr", "flir": "whois.nic.flir", "food": "whois.nic.food", "ford": "whois.nic.ford", "fox": "whois.nic.fox", "free": "whois.nic.free", "frontier": "whois.nic.frontier", "ftr": "whois.nic.ftr", "ga": "whois.my.ga", "gap": "whois.nic.gap", "gh": "whois.nic.gh", "gmo": "whois.nic.gmo", "got": "whois.nic.got", "grainger": "whois.nic.grainger", "grocery": "whois.nic.grocery", "guardian": "whois.nic.guardian", "gucci": "whois.nic.gucci", "hair": "whois.nic.hair", "hbo": "whois.nic.hbo", "health": "whois.nic.health", "homegoods": "whois.nic.homegoods", "homesense": "whois.nic.homesense", "honeywell": "whois.nic.honeywell", "hot": "whois.nic.hot", "hoteles": "whois.nic.hoteles", "hotels": "whois.nic.hotels", "hotmail": "whois.nic.hotmail", "hsbc": "whois.nic.hsbc", "htc": "whois.nic.htc", "hyatt": "whois.nic.hyatt", "ieee": "whois.nic.ieee", "iinet": "whois.nic.iinet", "imdb": "whois.nic.imdb", "int": "whois.iana.org", "intel": "whois.nic.intel", "intuit": "whois.nic.intuit", "ipiranga": " whois.nic.ipiranga", "ipirange": "whois.nic.ipiranga", "itau": "whois.nic.itau", "iwc": "whois.nic.iwc", "jetzt": "whois.nic.jetzt", "jlc": "whois.nic.jlc", "jmp": "whois.nic.jmp", "jnj": "whois.nic.jnj", "jot": "whois.nic.jot", "joy": "whois.nic.joy", "jpmorgan": "whois.nic.jpmorgan", "jprs": "whois.nic.jprs", "kinder": "whois.nic.kinder", "kindle": "whois.nic.kindle", "kpmg": "whois.nic.kpmg", "kpn": "whois.nic.kpn", "kred": "whois.nic.kred", "kw": "whois.nic.kw", "lanxess": "whois.nic.lanxess", "lc": "whois2.afilias-grs.net", "lifeinsurance": "whois.nic.lifeinsurance", "like": "whois.nic.like", "lilly": "whois.nic.lilly", "lincoln": "whois.nic.lincoln", "living": "whois.nic.living", "lk": "whois.nic.lk", "loft": "whois.nic.loft", "lupin": "whois.nic.lupin", "maif": "whois.nic.maif", "marshalls": "whois.nic.marshalls", "mattel": "whois.nic.mattel", "mcd": "whois.nic.mcd", "mcdonalds": "whois.nic.mcdonalds", "merckmsd": "whois.nic.merckmsd", "microsoft": "whois.nic.microsoft", "mint": "whois.nic.mint", "mlb": "whois.nic.mlb", "mobily": "whois.nic.mobily", "moi": "whois.nic.moi", "montblanc": "whois.nic.montblanc", "moto": "whois.nic.moto", "msd": "whois.nic.msd", "mtpc": "whois.nic.mtpc", "mutual": "whois.nic.mutual", "mutuelle": "whois.nic.mutuelle", "nagoya": "whois.nic.nagoya", "nba": "whois.nic.nba", "netflix": "whois.nic.netflix", "neustar": "whois.nic.neustar", "nfl": "whois.nic.nfl", "nhk": "whois.nic.nhk", "nike": "whois.nic.nike", "northwesternmutual": "whois.nic.northwesternmutual", "now": " whois.nic.now", "ntt": "whois.nic.ntt", "nyc": "whois.nic.nyc", "office": "whois.nic.office", "okinawa": "whois.nic.okinawa", "oldnavy": "whois.nic.oldnavy", "open": "whois.nic.open", "orientexpress": "whois.nic.orientexpress", "otsuka": "whois.nic.otsuka", "passagens": "whois.nic.passagens", "pay": "whois.nic.pay", "pfizer": "whois.nic.pfizer", "pharmacy": " whois.nic.pharmacy", "piaget": " whois.nic.piaget", "pictet": "whois.nic.pictet", "pin": "whois.nic.pin", "ping": "whois.nic.ping", "pramerica": "whois.nic.pramerica", "praxi": "whois.nic.praxi", "prime": "whois.nic.prime", "pru": "whois.nic.pru", "prudential": "whois.nic.prudential", "ps": "whois.pnina.ps", "qvc": "whois.nic.qvc", "read": "whois.nic.read", "realtor": "whois.nic.realtor", "ren": "whois.nic.ren", "rocher": "whois.nic.rocher", "room": "whois.nic.room", "rw": "whois.ricta.org.rw", "ryukyu": "whois.nic.ryukyu", "safe": "whois.nic.safe", "safety": "whois.nic.safety", "sakura": "whois.nic.sakura", "sapo": "whois.nic.sapo", "sas": "whois.nic.sas", "save": "whois.nic.save", "secure": "whois.nic.secure", "sener": "whois.nic.sener", "shaw": "whois.afilias-srs.net", "shop": "whois.nic.shop", "silk": "whois.nic.silk", "skype": "whois.nic.skype", "sl": "whois.nic.sl", "smile": "whois.nic.smile", "sohu": "whois.nic.sohu", "song": "whois.nic.song", "spot": "whois.nic.spot", "staples": "whois.nic.staples", "statefarm": "whois.nic.statefarm", "stream": "whois.nic.stream", "suzuki": "whois.nic.suzuki", "swiftcover": "whois.nic.swiftcover", "talk": "whois.nic.talk", "taobao": "whois.nic.taobao", "target": "whois.nic.target", "tjmaxx": "whois.nic.tjmaxx", "tjx": "whois.nic.tjx", "tkmaxx": "whois.nic.tkmaxx", "tmall": "whois.nic.tmall", "tokyo": "whois.nic.tokyo", "tube": "whois.nic.tube", "tunes": "whois.nic.tunes", "tushu": "whois.nic.tushu", "tvs": "whois.nic.tvs", "unicom": "whois.nic.unicom", "uno": "whois.nic.uno", "vivo": "whois.nic.vivo", "vuelos": "whois.nic.vuelos", "wanggou": "whois.nic.wanggou", "watches": "whois.nic.watches", "weather": "whois.nic.weather", "weatherchannel": "whois.nic.weatherchannel", "weir": "whois.nic.weir", "whois": "whois.nic.qpon", "windows": "whois.nic.windows", "winners": "whois.nic.winners", "wow": "whois.nic.wow", "xbox": "whois.nic.xbox", "xn--1ck2e1b": "whois.nic.xn--1ck2e1b", "xn--2scrj9c": "whois.inregistry.net", "xn--3hcrj9c": "whois.inregistry.net", "xn--45br5cyl": "whois.inregistry.net", "xn--45brj9c": "whois.inregistry.net", "xn--8y0a063a": "whois.nic.xn--8y0a063a", "xn--bck1b9a5dre4c": "whois.nic.xn--bck1b9a5dre4c", "xn--cck2b3b": "whois.nic.xn--cck2b3b", "xn--czr694b": "whois.nic.xn--czr694b", "xn--e1a4c": "whois.eu", "xn--eckvdtc9d": "whois.nic.xn--eckvdtc9d", "xn--fct429k": "whois.nic.xn--fct429k", "xn--fpcrj9c3d": "whois.inregistry.net", "xn--fzc2c9e2c": "whois.nic.lk", "xn--g2xx48c": "whois.nic.xn--g2xx48c", "xn--gckr3f0f": "whois.nic.xn--gckr3f0f", "xn--gecrj9c": "whois.inregistry.net", "xn--gk3at1e": "whois.nic.xn--gk3at1e", "xn--h2breg3eve": "whois.inregistry.net", "xn--h2brj9c": "whois.inregistry.net", "xn--h2brj9c8c": "whois.inregistry.net", "xn--imr513n": "whois.nic.xn--imr513n", "xn--jvr189m": "whois.nic.xn--jvr189m", "xn--kpu716f": "whois.nic.xn--kpu716f", "xn--mgba3a3ejt": "whois.nic.xn--mgba3a3ejt", "xn--mgbb9fbpob": "whois.nic.xn--mgbb9fbpob", "xn--mgbbh1a": "whois.inregistry.net", "xn--mgbbh1a71e": "whois.inregistry.net", "xn--mgbgu82a": "whois.inregistry.net", "xn--nyqy26a": "whois.nic.xn--nyqy26a", "xn--otu796d": "whois.nic.xn--otu796d", "xn--pbt977c": "whois.nic.xn--pbt977c", "xn--rhqv96g": "whois.nic.xn--rhqv96g", "xn--rovu88b": "whois.nic.xn--rovu88b", "xn--rvc1e0am3e": "whois.inregistry.net", "xn--s9brj9c": "whois.inregistry.net", "xn--ses554g": "whois.registry.knet.cn", "xn--wgbh1c": "whois.dotmasr.eg", "xn--xkc2al3hye2a": "whois.nic.lk", "xn--xkc2dl3a5ee0h": "whois.inregistry.net", "yahoo": "whois.nic.yahoo", "yamaxun": "whois.nic.yamaxun", "yandex": "whois.nic.yandex", "yokohama": "whois.nic.yokohama", "you": "whois.nic.you", "za": "whois.registry.net.za", "zappos": "whois.nic.zappos", "zero": "whois.nic.zero", "zippo": "whois.nic.zippo", }
class IANA: # pragma: no cover pylint: disable=too-few-public-methods """ Logic behind the update and usage of `iana-domains-db.json` """ def __init__(self): # We get the destination of the constructed IANA database. self.destination = (PyFunceble.CURRENT_DIRECTORY + PyFunceble.OUTPUTS["default_files"]["iana"]) if PyFunceble.path.isfile(self.destination): # The destination exist. # We get its content. self.iana_db = Dict().from_json(File(self.destination).read()) else: # The destination does not exist. # We initiate the local variable which will save the content of the database. self.iana_db = {} # We initiate the URL to the IANA Root Zone Database page. self.iana_url = "https://www.iana.org/domains/root/db" # We iniitate an instance of Lookup. self.lookup = Lookup() # We map the list of server which have to be set manually because # they are not present into the IANA Root Zone Database. self.manual_server = { "aaa": "whois.nic.aaa", "abb": "whois.nic.abb", "able": "whois.nic.able", "accenture": "whois.nic.accenture", "aetna": "whois.nic.aetna", "aig": "whois.nic.aig", "americanexpress": "whois.nic.americanexpress", "amex": "whois.nic.amex", "amica": "whois.nic.amica", "amsterdam": "whois.nic.amsterdam", "analytics": "whois.nic.analytics", "aramco": "whois.nic.aramco", "arte": "whois.nic.arte", "as": "whois.nic.as", "athleta": "whois.nic.athleta", "audible": "whois.nic.audible", "author": "whois.nic.author", "aws": "whois.nic.aws", "axa": "whois.nic.axa", "azure": "whois.nic.azure", "baby": "whois.nic.baby", "banamex": "whois.nic.banamex", "bananarepublic": "whois.nic.bananarepublic", "baseball": "whois.nic.baseball", "bharti": "whois.nic.bharti", "bing": "whois.nic.bing", "bloomberg": "whois.nic.bloomberg", "bm": "whois.afilias-srs.net", "book": "whois.nic.book", "booking": "whois.nic.booking", "bot": "whois.nic.bot", "buzz": "whois.nic.buzz", "bz": "whois.afilias-grs.net", "call": "whois.nic.call", "calvinklein": "whois.nic.calvinklein", "caravan": "whois.nic.caravan", "cartier": "whois.nic.cartier", "caseih": "whois.nic.caseih", "cbn": "whois.nic.cbn", "cbre": "whois.nic.cbre", "cd": "chois.nic.cd", "chase": "whois.nic.chase", "circle": "whois.nic.circle", "cisco": "whois.nic.cisco", "citadel": "whois.nic.citadel", "citi": "whois.nic.citi", "citic": "whois.nic.citic", "cm": "whois.netcom.cm", "coupon": "whois.nic.coupon", "crown": "whois.nic.crown", "crs": "whois.nic.crs", "deal": "whois.nic.deal", "dealer": "whois.nic.dealer", "dell": "whois.nic.dell", "dhl": "whois.nic.dhl", "discover": "whois.nic.discover", "dnp": "whois.nic.dnp", "doosan": "whois.nic.doosan", "duns": "whois.nic.duns", "dupont": "whois.nic.dupont", "earth": "whois.nic.earth", "energy": "whois.nic.energy", "epost": "whois.nic.epost", "everbank": "whois.nic.everbank", "farmers": "whois.nic.farmers", "fast": "whois.nic.fast", "ferrero": "whois.nic.ferrero", "fire": "whois.nic.fire", "fj": "whois.usp.ac.fj", "flickr": "whois.nic.flickr", "flir": "whois.nic.flir", "food": "whois.nic.food", "ford": "whois.nic.ford", "fox": "whois.nic.fox", "free": "whois.nic.free", "frontier": "whois.nic.frontier", "ftr": "whois.nic.ftr", "ga": "whois.my.ga", "gap": "whois.nic.gap", "gh": "whois.nic.gh", "gmo": "whois.nic.gmo", "got": "whois.nic.got", "grainger": "whois.nic.grainger", "grocery": "whois.nic.grocery", "guardian": "whois.nic.guardian", "gucci": "whois.nic.gucci", "hair": "whois.nic.hair", "hbo": "whois.nic.hbo", "health": "whois.nic.health", "homegoods": "whois.nic.homegoods", "homesense": "whois.nic.homesense", "honeywell": "whois.nic.honeywell", "hot": "whois.nic.hot", "hoteles": "whois.nic.hoteles", "hotels": "whois.nic.hotels", "hotmail": "whois.nic.hotmail", "hsbc": "whois.nic.hsbc", "htc": "whois.nic.htc", "hyatt": "whois.nic.hyatt", "ieee": "whois.nic.ieee", "iinet": "whois.nic.iinet", "imdb": "whois.nic.imdb", "int": "whois.iana.org", "intel": "whois.nic.intel", "intuit": "whois.nic.intuit", "ipiranga": " whois.nic.ipiranga", "ipirange": "whois.nic.ipiranga", "itau": "whois.nic.itau", "iwc": "whois.nic.iwc", "jetzt": "whois.nic.jetzt", "jlc": "whois.nic.jlc", "jmp": "whois.nic.jmp", "jnj": "whois.nic.jnj", "jot": "whois.nic.jot", "joy": "whois.nic.joy", "jpmorgan": "whois.nic.jpmorgan", "jprs": "whois.nic.jprs", "kinder": "whois.nic.kinder", "kindle": "whois.nic.kindle", "kpmg": "whois.nic.kpmg", "kpn": "whois.nic.kpn", "kred": "whois.nic.kred", "kw": "whois.nic.kw", "lanxess": "whois.nic.lanxess", "lc": "whois2.afilias-grs.net", "lifeinsurance": "whois.nic.lifeinsurance", "like": "whois.nic.like", "lilly": "whois.nic.lilly", "lincoln": "whois.nic.lincoln", "living": "whois.nic.living", "lk": "whois.nic.lk", "loft": "whois.nic.loft", "lupin": "whois.nic.lupin", "maif": "whois.nic.maif", "marshalls": "whois.nic.marshalls", "mattel": "whois.nic.mattel", "mcd": "whois.nic.mcd", "mcdonalds": "whois.nic.mcdonalds", "merckmsd": "whois.nic.merckmsd", "microsoft": "whois.nic.microsoft", "mint": "whois.nic.mint", "mlb": "whois.nic.mlb", "mobily": "whois.nic.mobily", "moi": "whois.nic.moi", "montblanc": "whois.nic.montblanc", "moto": "whois.nic.moto", "msd": "whois.nic.msd", "mtpc": "whois.nic.mtpc", "mutual": "whois.nic.mutual", "mutuelle": "whois.nic.mutuelle", "nagoya": "whois.nic.nagoya", "nba": "whois.nic.nba", "netflix": "whois.nic.netflix", "neustar": "whois.nic.neustar", "nfl": "whois.nic.nfl", "nhk": "whois.nic.nhk", "nike": "whois.nic.nike", "northwesternmutual": "whois.nic.northwesternmutual", "now": " whois.nic.now", "ntt": "whois.nic.ntt", "nyc": "whois.nic.nyc", "office": "whois.nic.office", "okinawa": "whois.nic.okinawa", "oldnavy": "whois.nic.oldnavy", "open": "whois.nic.open", "orientexpress": "whois.nic.orientexpress", "otsuka": "whois.nic.otsuka", "passagens": "whois.nic.passagens", "pay": "whois.nic.pay", "pfizer": "whois.nic.pfizer", "pharmacy": " whois.nic.pharmacy", "piaget": " whois.nic.piaget", "pictet": "whois.nic.pictet", "pin": "whois.nic.pin", "ping": "whois.nic.ping", "pramerica": "whois.nic.pramerica", "praxi": "whois.nic.praxi", "prime": "whois.nic.prime", "pru": "whois.nic.pru", "prudential": "whois.nic.prudential", "ps": "whois.pnina.ps", "qvc": "whois.nic.qvc", "read": "whois.nic.read", "realtor": "whois.nic.realtor", "ren": "whois.nic.ren", "rocher": "whois.nic.rocher", "room": "whois.nic.room", "rw": "whois.ricta.org.rw", "ryukyu": "whois.nic.ryukyu", "safe": "whois.nic.safe", "safety": "whois.nic.safety", "sakura": "whois.nic.sakura", "sapo": "whois.nic.sapo", "sas": "whois.nic.sas", "save": "whois.nic.save", "secure": "whois.nic.secure", "sener": "whois.nic.sener", "shaw": "whois.afilias-srs.net", "shop": "whois.nic.shop", "silk": "whois.nic.silk", "skype": "whois.nic.skype", "sl": "whois.nic.sl", "smile": "whois.nic.smile", "sohu": "whois.nic.sohu", "song": "whois.nic.song", "spot": "whois.nic.spot", "staples": "whois.nic.staples", "statefarm": "whois.nic.statefarm", "stream": "whois.nic.stream", "suzuki": "whois.nic.suzuki", "swiftcover": "whois.nic.swiftcover", "talk": "whois.nic.talk", "taobao": "whois.nic.taobao", "target": "whois.nic.target", "tjmaxx": "whois.nic.tjmaxx", "tjx": "whois.nic.tjx", "tkmaxx": "whois.nic.tkmaxx", "tmall": "whois.nic.tmall", "tokyo": "whois.nic.tokyo", "tube": "whois.nic.tube", "tunes": "whois.nic.tunes", "tushu": "whois.nic.tushu", "tvs": "whois.nic.tvs", "unicom": "whois.nic.unicom", "uno": "whois.nic.uno", "vivo": "whois.nic.vivo", "vuelos": "whois.nic.vuelos", "wanggou": "whois.nic.wanggou", "watches": "whois.nic.watches", "weather": "whois.nic.weather", "weatherchannel": "whois.nic.weatherchannel", "weir": "whois.nic.weir", "whois": "whois.nic.qpon", "windows": "whois.nic.windows", "winners": "whois.nic.winners", "wow": "whois.nic.wow", "xbox": "whois.nic.xbox", "xn--1ck2e1b": "whois.nic.xn--1ck2e1b", "xn--2scrj9c": "whois.inregistry.net", "xn--3hcrj9c": "whois.inregistry.net", "xn--45br5cyl": "whois.inregistry.net", "xn--45brj9c": "whois.inregistry.net", "xn--8y0a063a": "whois.nic.xn--8y0a063a", "xn--bck1b9a5dre4c": "whois.nic.xn--bck1b9a5dre4c", "xn--cck2b3b": "whois.nic.xn--cck2b3b", "xn--czr694b": "whois.nic.xn--czr694b", "xn--e1a4c": "whois.eu", "xn--eckvdtc9d": "whois.nic.xn--eckvdtc9d", "xn--fct429k": "whois.nic.xn--fct429k", "xn--fpcrj9c3d": "whois.inregistry.net", "xn--fzc2c9e2c": "whois.nic.lk", "xn--g2xx48c": "whois.nic.xn--g2xx48c", "xn--gckr3f0f": "whois.nic.xn--gckr3f0f", "xn--gecrj9c": "whois.inregistry.net", "xn--gk3at1e": "whois.nic.xn--gk3at1e", "xn--h2breg3eve": "whois.inregistry.net", "xn--h2brj9c": "whois.inregistry.net", "xn--h2brj9c8c": "whois.inregistry.net", "xn--imr513n": "whois.nic.xn--imr513n", "xn--jvr189m": "whois.nic.xn--jvr189m", "xn--kpu716f": "whois.nic.xn--kpu716f", "xn--mgba3a3ejt": "whois.nic.xn--mgba3a3ejt", "xn--mgbb9fbpob": "whois.nic.xn--mgbb9fbpob", "xn--mgbbh1a": "whois.inregistry.net", "xn--mgbbh1a71e": "whois.inregistry.net", "xn--mgbgu82a": "whois.inregistry.net", "xn--nyqy26a": "whois.nic.xn--nyqy26a", "xn--otu796d": "whois.nic.xn--otu796d", "xn--pbt977c": "whois.nic.xn--pbt977c", "xn--rhqv96g": "whois.nic.xn--rhqv96g", "xn--rovu88b": "whois.nic.xn--rovu88b", "xn--rvc1e0am3e": "whois.inregistry.net", "xn--s9brj9c": "whois.inregistry.net", "xn--ses554g": "whois.registry.knet.cn", "xn--wgbh1c": "whois.dotmasr.eg", "xn--xkc2al3hye2a": "whois.nic.lk", "xn--xkc2dl3a5ee0h": "whois.inregistry.net", "yahoo": "whois.nic.yahoo", "yamaxun": "whois.nic.yamaxun", "yandex": "whois.nic.yandex", "yokohama": "whois.nic.yokohama", "you": "whois.nic.you", "za": "whois.registry.net.za", "zappos": "whois.nic.zappos", "zero": "whois.nic.zero", "zippo": "whois.nic.zippo", } def load(self): """ Initiate the IANA database if it is not the case. """ if "iana_db" not in PyFunceble.INTERN or not PyFunceble.INTERN[ "iana_db"]: # The global database is empty, None or does not exist. # We update it with the database content. PyFunceble.INTERN["iana_db"] = self.iana_db def _referer(self, extension): """ Return the referer for the given extension. :param extension: A valid domain extension. :type extension: str :return: The whois server to use to get the WHOIS record. :rtype: str """ # We get the a copy of the page. iana_record = self.lookup.whois( PyFunceble.CONFIGURATION["iana_whois_server"], "hello.%s" % extension) if iana_record and "refer" in iana_record: # The record is not empty. # We initiate a regex which will extract the referer. regex_referer = r"(?s)refer\:\s+([a-zA-Z0-9._-]+)\n" # We try to extract the referer. matched = Regex(iana_record, regex_referer, return_data=True, group=1).match() if matched: # The referer was extracted successfully. # We return the matched referer. return matched # * The referer was not extracted successfully. # or # * The iana record is empty. if extension in self.manual_server: # The extension is in the list of manual entries. # We return the server which we set manually. return self.manual_server[extension] # We return None because we weren't able to get the server to call for # the given extension. return None def _extensions(self): """ Extract the extention from the given block. Plus get its referer. """ upstream_lines = (Download( self.iana_url, return_data=True).text().split('<span class="domain tld">')) # We extract the different extension from the currently readed line. regex_valid_extension = r"(/domains/root/db/)(.*)(\.html)" for block in upstream_lines: if "/domains/root/db/" in block: # The link is in the line. # We try to extract the extension. matched = Regex(block, regex_valid_extension, return_data=True, rematch=True).match()[1] if matched: # The extraction is not empty or None. # We get the referer. referer = self._referer(matched) # We yield the matched extension and its referer. yield (matched, referer) def update(self): """ Update the content of the `iana-domains-db` file. """ if not PyFunceble.CONFIGURATION["quiet"]: # * The quiet mode is not activated. # We print on screen what we are doing. print("Update of iana-domains-db", end=" ") # We loop through the line of the iana website. for extension, referer in self._extensions(): if extension not in self.iana_db or self.iana_db[ extension] != referer: # We add the extension to the databae. self.iana_db[extension] = referer # We save the content of the constructed database. Dict(self.iana_db).to_json(self.destination) if not PyFunceble.CONFIGURATION["quiet"]: # The quiet mode is not activated. # We indicate that the work is done without any issue. print(PyFunceble.INTERN["done"])
def _extract(self): # pragma: no cover """ Extract the expiration date from the whois record. """ self.whois_record = Lookup().whois(PyFunceble.CONFIGURATION["referer"]) to_match = [ r"expire:(.*)", r"expire on:(.*)", r"Expiry Date:(.*)", r"free-date(.*)", r"expires:(.*)", r"Expiration date:(.*)", r"Expiry date:(.*)", r"Expire Date:(.*)", r"renewal date:(.*)", r"Expires:(.*)", r"validity:(.*)", r"Expiration Date :(.*)", r"Expiry :(.*)", r"expires at:(.*)", r"domain_datebilleduntil:(.*)", r"Data de expiração \/ Expiration Date \(dd\/mm\/yyyy\):(.*)", r"Fecha de expiración \(Expiration date\):(.*)", r"\[Expires on\](.*)", r"Record expires on(.*)(\(YYYY-MM-DD\))", r"status: OK-UNTIL(.*)", r"renewal:(.*)", r"expires............:(.*)", r"expire-date:(.*)", r"Exp date:(.*)", r"Valid-date(.*)", r"Expires On:(.*)", r"Fecha de vencimiento:(.*)", r"Expiration:.........(.*)", r"Fecha de Vencimiento:(.*)", r"Registry Expiry Date:(.*)", r"Expires on..............:(.*)", r"Expiration Time:(.*)", r"Expiration Date:(.*)", r"Expired:(.*)", r"Date d'expiration:(.*)", ] if self.whois_record: for string in to_match: expiration_date = Regex( self.whois_record, string, return_data=True, rematch=True, group=0 ).match() if expiration_date: self.expiration_date = expiration_date[0].strip() regex_rumbers = r"[0-9]" if Regex( self.expiration_date, regex_rumbers, return_data=False ).match(): self.expiration_date = self._format() if self.expiration_date and not Regex( self.expiration_date, r"[0-9]{2}\-[a-z]{3}\-2[0-9]{3}", return_data=False, ).match(): self.log() self._whois_log() Generate( PyFunceble.STATUS["official"]["up"], "WHOIS", self.expiration_date, ).status_file() self._whois_log() return PyFunceble.STATUS["official"]["up"] self._whois_log() return Status(PyFunceble.STATUS["official"]["down"]).handle() self._whois_log() return Status(PyFunceble.STATUS["official"]["down"]).handle()