DnsNameResolver 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DnsNameResolver --version 1.0.0
NuGet\Install-Package DnsNameResolver -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DnsNameResolver" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DnsNameResolver --version 1.0.0
#r "nuget: DnsNameResolver, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DnsNameResolver as a Cake Addin
#addin nuget:?package=DnsNameResolver&version=1.0.0

// Install DnsNameResolver as a Cake Tool
#tool nuget:?package=DnsNameResolver&version=1.0.0

DnsResolver

C# async wrapper for DnsQueryEx using C++ to call native method.

Example

// LONG is the same size as int in Windows
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void CallbackDelegate(int status, string ipAddress, uint ttl);

public enum DnsRecordTypes: ushort
{
    DNS_TYPE_A = 0x0001,
    DNS_TYPE_AAAA = 0x001c,
}

static async Task Main(string[] args)
{
    var result = await GetHostAddressAsync("www.bing.com").ConfigureAwait(false);
    Console.WriteLine($"Result: {result}");
    Console.ReadKey();
}

static async Task<Tuple<string, uint>> GetHostAddressAsync(string hostname, DnsRecordTypes type = DnsRecordTypes.DNS_TYPE_A)
{
    var taskWrapper = new TaskCompletionSource<Tuple<string, uint>>();
    var callback = new CallbackDelegate(
        (status, ipAddress, ttl) =>
        {
            if (status != 0)
            {
                taskWrapper.SetException(new Exception($"DNS query for {hostname} failed. ErrorCode: {status}"));
                return;
            }

            Console.WriteLine($"Status: {status} | IP: {ipAddress} | TTL: {ttl}");
            taskWrapper.SetResult(Tuple.Create(ipAddress, ttl));
        });

    ResolveDns(hostname, type, callback);
    return await taskWrapper.Task;
}

// You can get the entry point by using VS Command Prompt
// > dumpbin /exports DnsResolver.dll
[DllImport("DnsNameResolver.dll", EntryPoint = @"ResolveDnsName", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
internal static extern void ResolveDns(string hostname, DnsRecordTypes type, CallbackDelegate callback);
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 544 2/27/2020
1.0.0 450 2/26/2020