0

I have domains stored in the database and I want a reliable way of getting the root down so I can do an mx lookup on it.

For instance domains can appear like:

www.domain.com
www.domain.co.uk
domain.co.uk
domain.com
sub.domain.co.uk
sub.domain.com
... etc ... with any valid TLD that may have one or more periods.

I just want "domain.tld"

The only way I can see to do it it to maintain a database of TLD's. Is there a simpler way or is there any nuget package or existing library to help?

Edit:

Removing the www with regex does not fix this as www is not the only type of subdomain. Also just taking the top level domain doesn't work as many countries us the second level domain also.

Guerrilla
  • 13,375
  • 31
  • 109
  • 210
  • Possible duplicate of [Top level domain from URL in C#](http://stackoverflow.com/questions/4643227/top-level-domain-from-url-in-c-sharp) – Keith Nicholas Sep 21 '16 at 03:09
  • please do searches in SO before asking questions, there are many questions asking the same thing in a variety of languages with a variety of solutions already – Keith Nicholas Sep 21 '16 at 03:10
  • The linked answer does not answer this question. Removing with regex or taking top level only does not work as some countries use second level also. – Guerrilla Sep 21 '16 at 03:21

0 Answers0