Question

I need to determine whether a domain entered by a user is a standard domain e.g example.co.uk or just the TLD e.g co.uk.

Is there a way I can do this e.g. by querying nameservers using nslookup or dig commands?

Just for background, I'm building a tool which works with subdomains e.g. sub.domain.example.co.uk and need to be able to spilt each part of the subdomain into subdomain, domain and TLD parts.

Thanks,

Tom

Was it helpful?

Solution

The "problem" you are trying to solve isn't even well-defined.

There is no way to get this information from DNS itself. DNS makes no distinction between what you call a subdomain, a domain, and a TLD.

Browser makers and other interested parties have apparently not found any solution to this short of building and maintaining a list manually. And even that's an incomplete solution. For example, I know that in Canada you can register a domain as <your-label>.ca, <your-label>.<province>.ca, or <your-label>.<municipality>.<province>.ca, but the current version of Mozilla's list only accounts for the first two possibilities. (Listing all municipalities would be too burdensome anyway).

More importantly, the boundary between what is a "public" domain and a "private" domain isn't a technical one. You're not supposed to be able to register a domain under ac.jp unless you are a university (or similar) in Japan. You're not supposed to be able to register a domain under u-tokyo.ac.jp unless you are a department inside 東大 (or similar). Those two restrictions aren't fundamentally different on a technical level, yet one of those domains is considered "public" and the other one is not. It's a difference of politics/law.

Furthermore, if the public/private domain distinction is being used for security purposes (as it is used for example in web browsers to disallow supercookies), who says that different departments inside one university don't distrust each other just as much as different universities do? There's a well known piece of advice that applies: you shouldn't attempt to solve a political problem with a technical solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top