Coder Social home page Coder Social logo

filippoquaranta / nager.publicsuffix Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nager/nager.publicsuffix

0.0 3.0 0.0 242 KB

C# publicsuffix domain parser

License: MIT License

C# 91.08% JavaScript 0.92% CSS 0.78% HTML 6.99% PowerShell 0.23%

nager.publicsuffix's Introduction

Nager.PublicSuffix

The TLD proliferation makes it difficult to check domain names are valid. This project use the rules of publicsuffix.org a list of known public domain suffixes (TLD) to validate and split domains in the parts (tld, domain, subdomain). The validation rules are load direct from https://publicsuffix.org.

A domain name has 3 major parts:

TLD Domain Subdomain
com google blog
org wikipedia www
ru yandex mail

Website

https://publicsuffix.nager.at/

nuget

The package is available on nuget

PM> install-package Nager.PublicSuffix

Benefits

  • Very fast
  • Integrated cache
  • Async

Donation possibilities

If this project help you reduce time to develop, you can give me a beer ๐Ÿบ Donate

Examples

Load data from web (publicsuffix.org)

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

Load data from web change cache config

var webTldRuleProvider = new WebTldRuleProvider(cacheProvider: new FileCacheProvider(cacheTimeToLive: new TimeSpan(10, 0, 0))); //cache data for 10 hours

var domainParser = new DomainParser(webTldRuleProvider);
for (var i = 0; i < 100; i++)
{
	var isValid = webTldRuleProvider.CacheProvider.IsCacheValid();
	if (!isValid)
	{
		webTldRuleProvider.BuildAsync().GetAwaiter().GetResult(); //Reload data
	}
	
	var domainInfo = domainParser.Get($"sub{i}.test.co.uk");
}

Load data from file

var domainParser = new DomainParser(new FileTldRuleProvider("effective_tld_names.dat"));

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

nager.publicsuffix's People

Contributors

tinohager avatar phil-dobson-fh avatar louislouw avatar nazgaul avatar ronnykarlsson avatar phildobsonongithub avatar

Watchers

Filippo Quaranta avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.