2

i want to get the domain extention (at least i hope it is called this way) from the site name the user is currently on.

so from www.bbc.co.uk it's co.uk and www.google.com = .com https://stackoverflow.com/questions/ask = .com

etc.

especially the ones with the double name (like co.uk) gives me headaches....

EDIT as i understand from the comments, co.uk is not a top level domain? that makes life easier! EDIT new name (top level domain) in the title

Community
  • 1
  • 1
Michel
  • 23,085
  • 46
  • 152
  • 242

5 Answers5

3

It's called a toplevel domain (tld) but for the BBC that's just "uk", not "co.uk".

What you want does not follow a standard so you'll need a table to check 'potential' pseudo-tld's

H H
  • 263,252
  • 30
  • 330
  • 514
2

The .co.uk is the .co subdomain of the .uk tld. This question doesn't make sense in terms of the actual structure of dns.

Stuart
  • 575
  • 1
  • 3
  • 12
2

The PublicSuffix project from mozilla is the solution. It is a maintained list of TLD.

You can use the following nuget package Nager.PublicSuffix.

PM> Install-Package Nager.PublicSuffix

Example

var domainParser = new DomainParser(new WebTldRuleProvider());

var domainName = domainParser.Get("sub.test.co.uk");
//domainName.Domain = "test";
//domainName.Hostname = "sub.test.co.uk";
//domainName.RegistrableDomain = "test.co.uk";
//domainName.SubDomain = "sub";
//domainName.TLD = "co.uk";
live2
  • 3,771
  • 2
  • 37
  • 46
1

See this question

Regular expression to retrieve domain.tld

The .NET URI class can also retrieve the hostname, of course.

Community
  • 1
  • 1
Gelatin
  • 2,393
  • 1
  • 24
  • 29
0

It's called the Top Level Domain and then there's the first sub-domain, which not everyone uses. It's because the first DNS did reverse entries on the split list, to route faster, so it would've parsed to

uk -> co -> example -> www
jcolebrand
  • 15,889
  • 12
  • 75
  • 121