I occasionally stumble over a DNS country-code Top-Level domain (ccTLD) I don't immediately recognize for the simple reason that I don't know all ISO 3166-1 country-codes by heart. So I pop open a Web browser, use my favorite search engine, and the rest, well, you know how that goes.
$ whois -h whois.iana.org nl % IANA WHOIS server % for more information on IANA, visit http://www.iana.org % This query returned 1 object domain: NL organisation: SIDN (Stichting Internet Domeinregistratie Nederland) address: P.O. Box 5022 address: Arnhem 6802 EA address: Netherlands [...]
I've always thought it strange that the DNS, the huge, distributed, hierarchical database which contains all manner of "interesting stuff" doesn't have a zone I can query for the names of the country codes; at least I haven't found one (using my favorite search engine).
If I look at some of the text records published in the DNS for the ccTLDs I see very few which actually announce in which country they're located. In fact, in all the TLDs I found only ten records that satisfied my curiosity:
AO. IN TXT "Angola - http://www.dns.ao/" AT. IN TXT "The .at-zone is protected through the Austrian Copyright-Law [...] CG. IN TXT "Top-level Domain of the Republic of the Congo (Brazzaville)" CG. IN TXT "NIC Congo" CK. IN TXT "Cook Islands" CV. IN TXT "Cabo Verde" PL. IN TXT "ccTLD of Poland" PR. IN TXT "Puerto Rico Top Level Domain" RW. IN TXT "NIC Rwanda" ZA. IN TXT "Top-level domain for South Africa"
So guess what? Yep. ;-) Now don't complain: I know many people shudder at the thought of even more TXT records in the DNS, but there is a famous precedent. So without further ado, here's a way for you to query the country name from a 2-letter country code:
$ dig nl.cc.jpmens.net txt ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62990 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; ANSWER SECTION: nl.cc.jpmens.net. 14519 IN TXT "NETHERLANDS"
"nl" by the 2-letter country-code you wish to query, of course.
$ dig +short co.cc.jpmens.net txt "COLOMBIA"
I picked up on Maik's suggestion to add a few codes not in ISO 3166-1 and if you have any suggestions or wishes, feel free to speak up. And if anybody feels like providing a list of geo-coordinates per country-code (capital city, maybe?), we might be able to make something nice. ;-)
I've implemented Tony Finch's suggestion to redirect from
CC.cc.jpmens.net to the TLD's registry, not only for the ccTLDs but for all 310+ TLDs; COM, XXX, the IDN (internationalized) TLDs, and of course the ccTLDs, etc. should all work.
- If you visit cc.jpmens.net you'll be prompted for a TLD; enter it and be beamed over to the responsible NIC if there is one. (Some TLDs don't have their own NIC in which case we direct you to IANA's whois server.)
- If you visit, say, be.cc.jpmens.net you'll be directed automatically.
"be"by the TLD you're interested in.)
Unless I fidget too much with it, this interface ought to remain pretty stable.