YaWhois 1.0.0
See the version list below for details.
dotnet add package YaWhois --version 1.0.0
NuGet\Install-Package YaWhois -Version 1.0.0
<PackageReference Include="YaWhois" Version="1.0.0" />
paket add YaWhois --version 1.0.0
#r "nuget: YaWhois, 1.0.0"
// Install YaWhois as a Cake Addin #addin nuget:?package=YaWhois&version=1.0.0 // Install YaWhois as a Cake Tool #tool nuget:?package=YaWhois&version=1.0.0
YaWhois (dotnet) - Yet Another WHOIS Client Library
Description
This is a WHOIS client library written in .Net Standard 2.0 specification.
Why?
There are some WHOIS libraries were written in dotnet, but none of them satisfied of mine use cases. Previously, I have worked with whois program written by Marco d'Itri under Unix-like systems. And I like it.
YaWhois
repeats logic done by whois
program, specifically:
- Smart whois server selection for each query object.
- Server response processing (parsing) leaved to the application developer.
Usage
Hello, YaWhois!
var whois = new YaWhoisClient();
var response = whois.Query("github.com");
Console.WriteLine(response);
Using delegates
YaWhois
is using delegates to be easy in use.
var whois = new YaWhoisClient();
// set delegate when responses received
whois.ResponseParsed += Whois_ResponseParsed;
// make request
whois.Query("github.com");
static void Whois_ResponseParsed(object sender, YaWhoisClientEventArgs e)
{
YaWhoisClient whois = (YaWhoisClient)sender;
Console.WriteLine($"[server: {e.Server}]");
Console.WriteLine($"[query: {e.Query}]");
Console.WriteLine(e.Response);
}
Async method
Same as above, but use QueryAsync
method instead.
var whois = new YaWhoisClient();
whois.ResponseParsed += Whois_ResponseParsed;
// additional delegate for async queries
whois.ExceptionThrown += (o, e) =>
{
Console.WriteLine(e.Exception.Message);
};
// use cancellation token if neccessary
var cts = new CancellationTokenSource();
whois.QueryAsync("github.com", token: cts.Token);
// ...
Using delegates
All delegates have only two arguments:
object
sender (YaWhoisClient)YaWhoisClientEventArgs
args
The YaWhoisClientEventArgs
contains all information about your query:
object
Value - user object per queryIDataParser
Parser - parser to get referral information, you can set to yoursstring
Server - selected server (readonly)string
Query - adopted query to the selected server (readonly)Encoding
Encoding - server encoding (readonly)string
Response - when query is completed, it contains server response (readonly)string
Referral - referral server if server response contains this information (readonly)Exception
Exception - used byQueryAsync()
; contains exception if smth goes wrong (readonly)
General usage for user objects is passing them to Query()
or QueryAsync()
:
// your object for the query below
var mydata = new MyData();
whois.Query("github.com", value: mydata);
// access your data in any delegate, for instance
static void Whois_Delegate(object sender, YaWhoisClientEventArgs e)
{
var data = (MyData)e.Value;
// ...
}
BeforeSendRequest
This delegate called before request to a server.
Currently, this delegate has little purposes.
You may change IDataParser
Parser at this moment.
BeforeParseResponse
This one called after network request.
You may observe the string
Response value.
You still may change IDataParser
Parser at this moment.
ResponseParsed
This one called after parsing server response to find out
the value of Referral
.
This is last delegate to be called upon successful request.
Changing IDataParser
Parser value will not give any results.
ExceptionThrown
This is used only by QueryAsync()
method.
When called the exception is set to Exception
Exception
property of the YaWhoisClientEventArgs
arguments.
Recursive queries
YaWhoisClient
does recursive queries when its find referral from
the server response. If you wish disable this behaviour you may
set your dummy IDataParser
Parser.
An example to query IANA:
var whois = new YaWhoisClient();
// set delegate when responses received
whois.ResponseParsed += Whois_ResponseParsed;
// make request to IANA
whois.Query("github.com", "whois.iana.org");
// This delegate will be called for whois.iana.org response
// and a referral one (if it exists).
static void Whois_ResponseParsed(object sender, YaWhoisClientEventArgs e)
{
Console.WriteLine($"[server: {e.Server}]");
Console.WriteLine();
Console.WriteLine(e.Response);
}
Exceptions
There are special exceptions which may be thrown by YaWhoisClient
:
NoServerException
- when unable to find a server for this kind of objectUnknownNetworkException
- probably invalid AS number or IP address has been passedExternalWhoisException
- the server infromation is accessed by external resource
The Query()
method throws exceptions.
The QueryAsync()
method does not throws exceptions, instead it calls
the ExceptionThrown
delegate (see above for details).
See also
- RFC 3912 - WHOIS Protocol Specification
- github: rfc1036/whois - whois client written in C
- github: flipbit/whois - dotnet whois library
License
This software is released under BSD 2-clause "Simplified" License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Nunycode (>= 1.1.0)
- System.Memory (>= 4.5.4)
- System.Text.Encoding.CodePages (>= 4.7.1)
- TinyCsvParser (>= 2.5.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release.