Top level domain from URL in C#

后端 未结 7 1312
误落风尘
误落风尘 2020-11-29 10:11

I am using C# and ASP.NET for this.

We receive a lot of \"strange\" requests on our IIS 6.0 servers and I want to log and catalog these by domain.

Eg. we get

7条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 10:45

    You can use the following nuget Nager.PublicSuffix package. It uses the same data source that browser vendors use.

    nuget

    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";
    

提交回复
热议问题