Skip to content

Instantly share code, notes, and snippets.

@kjd
Last active August 30, 2022 23:27
Show Gist options
  • Save kjd/3b1141451c77e50e0ab1120caac40072 to your computer and use it in GitHub Desktop.
Save kjd/3b1141451c77e50e0ab1120caac40072 to your computer and use it in GitHub Desktop.
Which TLDs are not in the Public Suffix List?
#!/usr/bin/env python3
import requests, idna
PUBLIC_SUFFIX_URL = 'https://publicsuffix.org/list/public_suffix_list.dat'
DELEGATED_TLDS_URL = 'https://data.iana.org/TLD/tlds-alpha-by-domain.txt'
current_suffixes = [x for x in requests.get(PUBLIC_SUFFIX_URL).text.split('\n') if x and not x.startswith('//')]
current_tlds = [idna.decode(x) for x in requests.get(DELEGATED_TLDS_URL).text.split('\n') if x and not x.startswith('#')]
for tld in current_tlds:
if not tld in current_suffixes:
# Check if there are 2nd-level or below in the list
for suffix in current_suffixes:
if suffix.endswith('.'+tld):
break
else:
print("{} is not in the public-suffix list".format(tld))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment