Repository navigation
Expand file tree
/
Copy pathDNSLookup.cs
More file actions
56 lines (49 loc) · 2.31 KB
/
Copy pathDNSLookup.cs
File metadata and controls
56 lines (49 loc) · 2.31 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
52
53
54
55
56
using DnsClient;
using NETworkManager.Models.Network;
using NETworkManager.Settings;
using NETworkManager.Utilities;
namespace NETworkManager.Profiles.Application;
public static class DNSLookup
{
/// <summary>
/// Gets the DNS servers for a profile: its own DNS servers (if overridden), otherwise the DNS servers of its
/// group (if overridden), otherwise none (the DNS server selected in the DNS Lookup is used). DNS servers by name
/// with their current name (also after a rename); if a DNS server can't be found (deleted, or a profile file
/// shared from another computer - DNS servers are saved in the settings), the servers saved with the profile or
/// group.
/// </summary>
/// <param name="profile">Profile to get the DNS servers for.</param>
/// <param name="dnsServerNotFound">True if a DNS server can't be found.</param>
/// <returns>DNS servers, null if neither the profile nor its group has DNS servers.</returns>
public static string GetDNSServer(ProfileInfo profile, out bool dnsServerNotFound)
{
// Get group info
var group = ProfileManager.GetGroupByName(profile.Group);
var (dnsServer, dnsServerInput) = profile.DNSLookup_OverrideDNSServer
? (profile.DNSLookup_DNSServer, profile.DNSLookup_DNSServerInput)
: group.DNSLookup_OverrideDNSServer
? (group.DNSLookup_DNSServer, group.DNSLookup_DNSServerInput)
: (null, null);
if (string.IsNullOrWhiteSpace(dnsServer))
{
dnsServerNotFound = false;
return null;
}
return DNSServer.Decode(dnsServer, dnsServerInput, SettingsManager.Current.DNSLookup_DNSServers,
out dnsServerNotFound);
}
/// <summary>
/// Gets the query type for a profile: its own type (if overridden), otherwise PTR for IP addresses and A for
/// hostnames.
/// </summary>
/// <param name="profile">Profile to get the query type for.</param>
/// <returns>Query type.</returns>
public static QueryType GetQueryType(ProfileInfo profile)
{
return profile.DNSLookup_OverrideQueryType
? profile.DNSLookup_QueryType
: IPAddressHelper.AreIPAddresses(profile.DNSLookup_Host)
? QueryType.PTR
: QueryType.A;
}
}