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.