-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,54 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
using Nager.PublicSuffix; | ||
using Nager.PublicSuffix.RuleProviders; | ||
using Nager.PublicSuffix.RuleProviders.CacheProviders; | ||
|
||
using var loggerFactory = LoggerFactory.Create(builder => | ||
{ | ||
builder.AddConsole(); | ||
}); | ||
#region CachedHttpRuleProvider | ||
|
||
var logger = loggerFactory.CreateLogger("Program"); | ||
var ruleProviderLogger = loggerFactory.CreateLogger<CachedHttpRuleProvider>(); | ||
//using var loggerFactory = LoggerFactory.Create(builder => | ||
//{ | ||
// builder.AddConsole(); | ||
//}); | ||
|
||
IConfiguration configuration = new ConfigurationBuilder() | ||
.AddInMemoryCollection(new List<KeyValuePair<string, string?>> | ||
{ | ||
new("Nager:PublicSuffix:DataUrl", "https://publicsuffix.org/list/public_suffix_list1.dat") | ||
}) | ||
.Build(); | ||
//var ruleProviderLogger = loggerFactory.CreateLogger<CachedHttpRuleProvider>(); | ||
|
||
var httpClient = new HttpClient(); | ||
var cacheProvider = new LocalFileSystemCacheProvider(); | ||
//IConfiguration configuration = new ConfigurationBuilder() | ||
// .AddInMemoryCollection(new List<KeyValuePair<string, string?>> | ||
// { | ||
// new("Nager:PublicSuffix:DataUrl", "https://publicsuffix.org/list/public_suffix_list1.dat") | ||
// }) | ||
// .Build(); | ||
|
||
var ruleProvider = new CachedHttpRuleProvider(ruleProviderLogger, configuration, cacheProvider, httpClient); | ||
await ruleProvider.BuildAsync(ignoreCache: true); | ||
//var httpClient = new HttpClient(); | ||
//var cacheProvider = new Nager.PublicSuffix.RuleProviders.CacheProviders.LocalFileSystemCacheProvider(); | ||
|
||
//var ruleProvider = new CachedHttpRuleProvider(ruleProviderLogger, configuration, cacheProvider, httpClient); | ||
|
||
#endregion | ||
|
||
#region | ||
|
||
var ruleProvider = new SimpleHttpRuleProvider(); | ||
|
||
#endregion | ||
|
||
#region LocalFileRuleProvider | ||
|
||
//var ruleProvider = new LocalFileRuleProvider("public_suffix_list.dat"); | ||
|
||
#endregion | ||
|
||
await ruleProvider.BuildAsync(ignoreCache: true); | ||
|
||
var domainParser = new DomainParser(ruleProvider); | ||
var domainInfo = domainParser.Parse("www.google.com"); | ||
|
||
if (domainInfo != null) | ||
{ | ||
logger.LogInformation($"TLD:{domainInfo.TopLevelDomain}"); | ||
logger.LogInformation($"FQDN:{domainInfo.FullyQualifiedDomainName}"); | ||
logger.LogInformation($"RegistrableDomain:{domainInfo.RegistrableDomain}"); | ||
Console.WriteLine("------------------------------------------------"); | ||
Console.WriteLine($"{"TLD:", 20} {domainInfo.TopLevelDomain}"); | ||
Console.WriteLine($"{"FQDN:", 20} { domainInfo.FullyQualifiedDomainName}"); | ||
Console.WriteLine($"{"RegistrableDomain:", 20} {domainInfo.RegistrableDomain}"); | ||
Console.WriteLine($"{"Subdomain:",20} {domainInfo.Subdomain}"); | ||
Console.WriteLine("------------------------------------------------"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters