18

I found a lot of threads explaining how to get the country-codes in two- or three-letter format, but nothing that fits to my task. I'm heading for a way to get all the top level domains in an array or something. I know there's the CultureInfo class in C# but which could list the country codes. It doesn't include generic TLD, e.g.: "com". Here's the complete list of country codes I found.

kapex
  • 28,903
  • 6
  • 107
  • 121
user1826831
  • 735
  • 3
  • 9
  • 17
  • Do you mean top level domain names (TLDs)? Both the two-letter geographical TLDs and the non-geographical ones? – Dima Chubarov Jan 20 '13 at 18:36
  • Yes, I'm talking about the top level domain names. And yes, I need to get the geographical ones and the other ones. – user1826831 Jan 20 '13 at 18:47
  • 1
    Note: `.com` is *not* a country-code top-level domain (ccTLD), but a generic top-level domain (gTLD). – unor Jan 21 '13 at 17:35

2 Answers2

34

The authoritative list of all TLDs: http://www.iana.org/domains/root/db

The Root Zone Database represents the delegation details of top-level domains, including gTLDs such as .com, and country-code TLDs such as .uk.

You can get this as TXT, too (easier to parse): http://data.iana.org/TLD/tlds-alpha-by-domain.txt


Wikipedia also lists all TLDs, but it's not authoritative, of course: List of Internet top-level domains


The Mozilla Foundation maintains a Public Suffix List for effective top-level domains, i.e., those under which you can directly register names (for example .co.uk instead of .uk): http://publicsuffix.org/

unor
  • 92,415
  • 26
  • 211
  • 360
  • 1
    See also [tldextract](https://github.com/john-kurkowski/tldextract), which handles this problem very well and uses Mozilla's PSL, as pointed out by @unor. It is in Python, but you may be able to glean the way it handles certain cases from its source code. (A win, because the problem domain is full of nuisances.) – floer32 Jan 10 '14 at 16:28
  • the txt file only lists the TLDs but not whether they are country-codes or not. Do you know of a list that either provides this information or lists just TLDs of country-codes? – IttayD Jun 30 '15 at 06:44
  • @IttayD: In case you missed it: the first link contains a table with the column "Type", where it says "country-code" for ccTLDs. – unor Jun 30 '15 at 06:59
  • @unor: i didn't miss, but parsing html is a pain – IttayD Jul 01 '15 at 08:19
11

I like to use this list (it includes private TLDs): http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1. To me it's the most complete list I could find and it's in a plain text format.