Skip to content

Instantly share code, notes, and snippets.

@iokiwi
Created September 3, 2016 09:39
Show Gist options
  • Select an option

  • Save iokiwi/b294f7713c9d824f5063a289912cf5c8 to your computer and use it in GitHub Desktop.

Select an option

Save iokiwi/b294f7713c9d824f5063a289912cf5c8 to your computer and use it in GitHub Desktop.
import sys, urllib.request
url = "https://data.iana.org/TLD/tlds-alpha-by-domain.txt"
local_filename, headers = urllib.request.urlretrieve(url)
tlds = open(local_filename).readlines()
tlds = [tld.strip() for tld in tlds]
if len(sys.argv) > 1:
domain = sys.argv[1]
else:
domain = input("Enter a domain name: ")
substitunion_count = 0
for tld in tlds:
tld = tld.lower()
if domain.lower().endswith(tld):
substitunion_count += 1
print(domain[:domain.index(tld)] + "." + tld)
if substitunion_count == 0:
print("No top level domain name substitutions were found")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment