Code Monkey home page Code Monkey logo

flipbit_whois's Introduction

.NET WHOIS Lookup and Parser

GitHub Stars GitHub Issues NuGet Version NuGet Downloads

Query and parse WHOIS domain registration information with this library for .NET Standard 2.0 and .NET Framework 4.5.2.

var whois = new WhoisLookup();
var response = whois.Lookup("github.com");

Console.WriteLine(response.Content);

// Domain Name: github.com
// Registry Domain ID: 1264983250_DOMAIN_COM-VRSN
// Registrar WHOIS Server: whois.markmonitor.com
// Registrar URL: http://www.markmonitor.com
// ...

Parsing

WHOIS data is parsed into objects using extensible Tokenizer templates.

var response = whois.Lookup("github.com");
var json = JsonConvert.SerializeObject(response.ParsedResponse, Formatting.Indented);

Console.WriteLine(json);

// {
//   "DomainName": "github.com",
//   "RegistryDomainId": "1264983250_DOMAIN_COM-VRSN",
//   "Expiration": "2020-10-09T20:20:50+02:00",
//   "Registrar": {
//     "Name": "MarkMonitor, Inc.",
//     "Url": "http://www.markmonitor.com",
// ...

Async/Await

The library is fully async/await compatible.

public async Task<string> GetWhois()
{
    var whois = new WhoisLookup();
    var response = await whois.LookupAsync("github.com");
    return response.Content;
}

Configuration

The library can be configured globally or per instance:

// Global configuration
WhoisOptions.Defaults.DefaultEncoding = Encoding.ASCII;

// Instance configuration
var lookup = new WhoisLookup();
lookup.Options.ParseWhoisResponse = false;

Extending

Parsing More Data

If a registrar's WHOIS data isn't being parsed correctly, you can simply add a new template:

var lookup = new WhoisLookup();

// Clear embedded patterns
lookup.ClearPatterns()

// Add new pattern
lookup.AddPattern("Domain: {DomainName$}", "Simple Pattern")

See the existing patterns and Tokenizer documentation for information about creating patterns. You can also add validation and transformation functions to your patterns.

Networking

The library communicates via an ITcpReader interface. The default implementation will talk directly to a WHOIS server over port 43. You can change this behaviour by creating a new ITcpReader implementation and registering it the TcpReaderFactory:

// Custom implementation
class MyCustomTcpReader : ITcpReader
{
    ...
}

// Register
TcpReaderFactory.Bind(() => new MyCustomTcpReader());

Installation

You can install the library via the NuGet GUI or by entering the following command into the Package Manager Console:

Install-Package Whois

The source code is available on Github and can be downloaded and compiled.

Further Reading

Further details about how the library works can be found on this blog post.

flipbit_whois's People

Watchers

 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.