forked from dotnet/Kerberos.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPortableDnsImplementation.cs
More file actions
51 lines (44 loc) · 1.56 KB
/
PortableDnsImplementation.cs
File metadata and controls
51 lines (44 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using DnsClient;
using Kerberos.NET.Dns;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Kerberos.NET.PortableDns
{
internal class PortableDnsImplementation : IKerberosDnsQuery
{
static PortableDnsImplementation()
{
DnsQuery.RegisterImplementation(new PortableDnsImplementation());
}
public static LookupClientOptions Options { get; set; } = new LookupClientOptions();
private static LookupClient Create()
{
return new LookupClient(Options);
}
public async Task<IReadOnlyCollection<DnsRecord>> Query(string query, DnsRecordType type)
{
var client = Create();
var response = await client.QueryAsync(query, (QueryType)type);
var srvRecords = response.Answers.SrvRecords().Select(a => new DnsRecord
{
Name = a.DomainName,
Port = a.Port,
Priority = a.Priority,
Target = a.Target,
TimeToLive = a.TimeToLive,
Type = DnsRecordType.SRV,
Weight = a.Weight
}).ToList();
var merged = srvRecords.GroupBy(r => r.Name);
foreach (var srv in srvRecords)
{
var c1 = merged.Where(m => m.Key.Equals(srv.Target, StringComparison.InvariantCultureIgnoreCase));
var canon = c1.SelectMany(r => r);
srv.Canonical = canon.ToList();
}
return srvRecords;
}
}
}