Git Product home page Git Product logo

domainname-parser's Introduction

domainname-parser Build status NuGet

.NET domain name parsing library (uses http://publicsuffix.org rules)

Overview

A domain name has 3 major parts:

  • The top level domain, or TLD (like .com, .net, .info)
  • The domain name, or SLD (like google, microsoft, ebay)
  • The subdomain (like www, photos)

Parsing a domain name into it's 3 major parts sounds easy, but is no trivial task. What happens when you come across hosts like test.co.uk? What about hosts like www.parliament.uk?

From http://publicsuffix.org :

"Since there is no algorithmic method of finding the highest level at which a domain may be registered for a particular top-level domain (the policies differ with each registry), the only method is to create a list. This is the aim of the Public Suffix List."

The domain name parsing component uses the list of rules at www.publicsuffix.org to parse a domain name into 3 component parts.

There are 3 types of rules: 'Normal' domain rules, 'Wildcard' rules, and 'Exception' rules.

Quick Start

Download the latest release from the NuGet repository

Install-Package domainname-parser

Download the latest rules file from https://publicsuffix.org/list/ and configure your app.config to point to the rules file you just downloaded (see the sample app.config)

Example

Using the component is simple. Just use the constructor or the static TryParse method and pass in the complete host name string. The component will return the parsed domain in a DomainName component. It's as simple as that:

// Try parsing a 'wildcard' domain 
if (DomainName.TryParse("photos.verybritish.co.uk", out outDomain)) 
{ 
  // The domain should be parsed as 'verybritish' 
  Assert.AreEqual("verybritish", outDomain.Domain);
  
  // The TLD is 'co.uk' 
  Assert.AreEqual("co.uk", outDomain.TLD);
  
  // The SLD is just an alias for 'Domain': 
  Assert.AreEqual(outDomain.Domain, outDomain.SLD);
  
  // The subdomain is everything else to the left of the domain: 
  Assert.AreEqual("photos", outDomain.SubDomain); 
} 
else 
{ 
  Debug.WriteLine("Apparently, we couldn't parse photos.verybritish.co.uk"); 
}

Where can I get the latest rules list?

You can download the latest rules from the Public Suffix site: http://publicsuffix.org/list/

domainname-parser's People

Contributors

danesparza avatar whorchner avatar sheilak avatar orbintsoft avatar adecr 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.