Convert subdomain to domain name (sub TLD vs TLD)
Domanda
I have written a function that "extract" the domain from hostname. e.g.
www.domain.com -> domain.com
domain.net -> domain.net
www.domain.co.uk -> domain.co.uk
www.subdomain.domain.tx.us -> domain.tx.us
and so on.
However I was unable to find list of all subTDL's.
Function also return wrong result for domains such nominet.uk
Any suggestions where I can find all of them?
Or any other way to do same function, but with using let say DNS?
Soluzione 2
There is publicly available file describing all sub TLD's located at:
http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1
Altri suggerimenti
It's impossible to this using the DNS (or any other algorithm for that matter) as there's no formal definition of what is a "subdomain".
The only practical solution at the moment is the "public suffix" list available via http://publicsuffix.org/.
This list contains those domains known to the administrators where different subdomains are issued to different third parties.
Its primary use is to help enforce cross-domain security policies - for example a server for "foo.co.uk" mustn't be able to set a domain cookie on "co.uk" which is then served to any other subdomain.