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
// ...
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",
// ...
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;
}
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;
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.
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());
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 details about how the library works can be found on this blog post.