def test_countryNameFromTld_argument_tld_should_return_country_as_a_string( self): tlds = ['com', 'net', 'org', 'gov', 'mil'] for tld in tlds: with self.subTest(tld=tld): country_name = SpiderFootHelpers.countryNameFromTld(tld) self.assertIsInstance(country_name, str) self.assertEqual(country_name, "United States")
def detectCountryFromDomainName(self, srcDomain: str) -> str: """Lookup name of country from TLD of domain name. Args: srcDomain (str): domain Returns: str: country name """ if not isinstance(srcDomain, str): return None # Split domain into parts by '.' # Country TLDs are reserved domainParts = srcDomain.split(".") # Search for country TLD in the domain parts - reversed for part in domainParts[::-1]: country_name = SpiderFootHelpers.countryNameFromTld(part) if country_name: return country_name return None