Git Product home page Git Product logo

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.

// Create a WhoisLookup instance
var whois = new WhoisLookup();

// Query github.com
var response = whois.Lookup("github.com");

// Output the response
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.

// Query github.com
var response = whois.Lookup("github.com");

// Convert the response to JSON
var json = JsonConvert.SerializeObject(response, Formatting.Indented);

// Output the json 
Console.WriteLine(json);

// {
//   "ContentLength": 3730,
//   "Status": 1,
//   "DomainName": {
//     "IsPunyCode": false,
//     "IsTld": false,
//     "Tld": "com",
//     "Value": "github.com"
//   },
//   "RegistryDomainId": "1264983250_DOMAIN_COM-VRSN",
//   "DomainStatus": [
//     "clientUpdateProhibited",
//     "clientTransferProhibited",
//     "clientDeleteProhibited"
//   ],
//   "Registered": "2007-10-09T18:20:50Z",
//   "Updated": "2020-09-08T09:18:27Z",
//   "Expiration": "2022-10-09T07:00:00Z",
// ...

Async/Await

The library is fully async/await compatible.

// Create a WhoisLookup instance
var whois = new WhoisLookup();

// Query github.com
var response = await whois.LookupAsync("github.com");

// Output the json 
Console.WriteLine(response.Content);

Configuration

The library can be configured globally or per instance:

// Global configuration
WhoisOptions.Defaults.Encoding = Encoding.UTF8;

// Per-instance configuration
var lookup = new WhoisLookup();
lookup.Options.TimeoutSeconds = 30;

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 the embedded templates (not recommended)
lookup.Parser.ClearTemplates();

// Add a custom WHOIS response parsing template
lookup.Parser.AddTemplate("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:

// Create a custom ITcpReader implementation
class MyCustomTcpReader : ITcpReader
{
  private readonly ITcpReader reader;

  public MyCustomTcpReader()
  {
     reader = new TcpReader();
  }

  public Task<string> Read(string url, int port, string command, Encoding encoding, int timeoutSeconds)
  {
    Console.WriteLine($"Reading from URL: {url}");

    return reader.Read(url, port, command, encoding, timeoutSeconds);
  }

  public void Dispose()
  {
    reader.Dispose();
  }
}

// Create a WhoisLookup instance
var lookup = new WhoisLookup();

// Assign the custom TcpReader
lookup.TcpReader = new MyCustomTcpReader();

// Lookups will now use the custom TcpReader
var response = lookup.Lookup("github.com");

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.

whois's People

Contributors

ajh16 avatar augustoproiete avatar dependabot-preview[bot] avatar dependabot[bot] avatar flipbit avatar nrkirby avatar sonicgd avatar txdv 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.