Skip to content

Commit 027b11b

Browse files
committed
Feature: Enter dns server in ui
1 parent d6eb3cc commit 027b11b

File tree

7 files changed

+117
-77
lines changed

7 files changed

+117
-77
lines changed

Source/GlobalAssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
[assembly: AssemblyTrademark("")]
77
[assembly: AssemblyCulture("")]
88

9-
[assembly: AssemblyVersion("2025.11.16.0")]
10-
[assembly: AssemblyFileVersion("2025.11.16.0")]
9+
[assembly: AssemblyVersion("2025.12.10.0")]
10+
[assembly: AssemblyFileVersion("2025.12.10.0")]

Source/NETworkManager.Models/Network/DNSLookupErrorArgs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class DNSLookupErrorArgs : EventArgs
66
{
77
public DNSLookupErrorArgs()
88
{
9+
910
}
1011

1112
public DNSLookupErrorArgs(string query, string server, string ipEndPoint, string errorMessage)

Source/NETworkManager.Models/Network/DNSServerConnectionInfoProfile.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public DNSServerConnectionInfoProfile()
2424
/// <param name="servers">List of servers as <see cref="ServerConnectionInfo" />.</param>
2525
public DNSServerConnectionInfoProfile(string name, List<ServerConnectionInfo> servers) : base(name, servers)
2626
{
27+
2728
}
2829

2930
/// <summary>

Source/NETworkManager.Settings/SettingsInfo.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ public ExportFileType Traceroute_ExportFileType
17231723

17241724
#region DNS Lookup
17251725

1726-
private ObservableCollection<string> _dnsLookup_HostHistory = new();
1726+
private ObservableCollection<string> _dnsLookup_HostHistory = [];
17271727

17281728
public ObservableCollection<string> DNSLookup_HostHistory
17291729
{
@@ -1738,7 +1738,7 @@ public ObservableCollection<string> DNSLookup_HostHistory
17381738
}
17391739
}
17401740

1741-
private ObservableCollection<DNSServerConnectionInfoProfile> _dnsLookup_DNSServers = new();
1741+
private ObservableCollection<DNSServerConnectionInfoProfile> _dnsLookup_DNSServers = [];
17421742

17431743
public ObservableCollection<DNSServerConnectionInfoProfile> DNSLookup_DNSServers
17441744
{
@@ -1753,8 +1753,10 @@ public ObservableCollection<DNSServerConnectionInfoProfile> DNSLookup_DNSServers
17531753
}
17541754
}
17551755

1756+
[Obsolete("Use DNSLookup_SelectedDNSServer_v2 instead.")]
17561757
private DNSServerConnectionInfoProfile _dnsLookup_SelectedDNSServer = null;
17571758

1759+
[Obsolete("Use DNSLookup_SelectedDNSServer_v2 instead.")]
17581760
public DNSServerConnectionInfoProfile DNSLookup_SelectedDNSServer
17591761
{
17601762
get => _dnsLookup_SelectedDNSServer;
@@ -1768,37 +1770,35 @@ public DNSServerConnectionInfoProfile DNSLookup_SelectedDNSServer
17681770
}
17691771
}
17701772

1771-
private QueryClass _dnsLookup_QueryClass = GlobalStaticConfiguration.DNSLookup_QueryClass;
1773+
private string _dnsLookup_SelectedDNSServer_v2;
17721774

1773-
public QueryClass DNSLookup_QueryClass
1775+
public string DNSLookup_SelectedDNSServer_v2
17741776
{
1775-
get => _dnsLookup_QueryClass;
1777+
get => _dnsLookup_SelectedDNSServer_v2;
17761778
set
17771779
{
1778-
if (value == _dnsLookup_QueryClass)
1780+
if (value == _dnsLookup_SelectedDNSServer_v2)
17791781
return;
17801782

1781-
_dnsLookup_QueryClass = value;
1783+
_dnsLookup_SelectedDNSServer_v2 = value;
17821784
OnPropertyChanged();
17831785
}
17841786
}
17851787

1786-
/*
1787-
private bool _dnsLookup_ShowOnlyMostCommonQueryTypes = true;
1788+
private QueryClass _dnsLookup_QueryClass = GlobalStaticConfiguration.DNSLookup_QueryClass;
17881789

1789-
public bool DNSLookup_ShowOnlyMostCommonQueryTypes
1790+
public QueryClass DNSLookup_QueryClass
17901791
{
1791-
get => _dnsLookup_ShowOnlyMostCommonQueryTypes;
1792+
get => _dnsLookup_QueryClass;
17921793
set
17931794
{
1794-
if (value == _dnsLookup_ShowOnlyMostCommonQueryTypes)
1795+
if (value == _dnsLookup_QueryClass)
17951796
return;
17961797

1797-
_dnsLookup_ShowOnlyMostCommonQueryTypes = value;
1798+
_dnsLookup_QueryClass = value;
17981799
OnPropertyChanged();
17991800
}
18001801
}
1801-
*/
18021802

18031803
private QueryType _dnsLookup_QueryType = GlobalStaticConfiguration.DNSLookup_QueryType;
18041804

Source/NETworkManager.Settings/SettingsManager.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,16 @@ private static void UpgradeToLatest(Version version)
337337
{
338338
Log.Info($"Apply upgrade to {version}...");
339339

340+
// DNS Lookup
341+
342+
Log.Info("Migrate DNS Lookup settings to new structure...");
343+
344+
Current.DNSLookup_SelectedDNSServer_v2 = Current.DNSLookup_SelectedDNSServer?.Name;
345+
346+
Log.Info($"Selected DNS server set to \"{Current.DNSLookup_SelectedDNSServer_v2}\"");
347+
348+
// AWS Session Manager
349+
340350
Log.Info("Removing deprecated app \"AWS Session Manager\", if it exists...");
341351

342352
var appToRemove = Current.General_ApplicationList

Source/NETworkManager/ViewModels/DNSLookupViewModel.cs

Lines changed: 85 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -81,77 +81,50 @@ public string Host
8181
/// <summary>
8282
/// Backing field for <see cref="DNSServer"/>.
8383
/// </summary>
84-
private DNSServerConnectionInfoProfile _dnsServer = new();
84+
private string _dnsServer;
8585

8686
/// <summary>
8787
/// Gets or sets the selected DNS server.
88+
/// This can either be an ip/host:port or a profile name.
8889
/// </summary>
89-
public DNSServerConnectionInfoProfile DNSServer
90+
public string DNSServer
9091
{
9192
get => _dnsServer;
92-
private set
93+
set
9394
{
9495
if (_dnsServer == value)
9596
return;
96-
97-
_dnsServer = value ?? new DNSServerConnectionInfoProfile();
9897

99-
if (!_isLoading)
100-
SettingsManager.Current.DNSLookup_SelectedDNSServer = _dnsServer;
101-
102-
OnPropertyChanged();
103-
}
104-
}
98+
// Try finding matching dns server profile by name, otherwise set to null (de-select)
99+
SelectedDNSServer = SettingsManager.Current.DNSLookup_DNSServers
100+
.FirstOrDefault(x => x.Name == value);
105101

106-
private DNSServerConnectionInfoProfile _selectedListProfile;
107-
public DNSServerConnectionInfoProfile SelectedListProfile
108-
{
109-
get => _selectedListProfile;
110-
set
111-
{
112-
if (_selectedListProfile == value)
113-
return;
114-
115-
if (value != null)
116-
{
117-
DNSServer = value;
118-
DNSServerQuickInput = value.ToString(); // uses your override
119-
}
102+
if (!_isLoading)
103+
SettingsManager.Current.DNSLookup_SelectedDNSServer_v2 = value;
120104

121-
_selectedListProfile = value;
105+
_dnsServer = value;
122106
OnPropertyChanged();
123107
}
124108
}
125109

126-
// Text box content
127-
private string _dnsServerQuickInput = string.Empty;
128-
public string DNSServerQuickInput
110+
private DNSServerConnectionInfoProfile _selectedDNSServer;
111+
public DNSServerConnectionInfoProfile SelectedDNSServer
129112
{
130-
get => _dnsServerQuickInput;
113+
get => _selectedDNSServer;
131114
set
132115
{
133-
if (_dnsServerQuickInput == value)
116+
if (_selectedDNSServer == value)
134117
return;
135118

136-
_dnsServerQuickInput = value?.Trim() ?? string.Empty;
119+
_selectedDNSServer = value;
137120
OnPropertyChanged();
138-
139-
// As soon as user types → deselect any list item
140-
SelectedListProfile = null;
141-
142-
// Create custom profile from raw IP
143-
if (IPAddress.TryParse(_dnsServerQuickInput, out IPAddress x))
144-
{
145-
// Temporarily switch to this custom profile
146-
DNSServer = new DNSServerConnectionInfoProfile("CUSTOM", [new ServerConnectionInfo(x.ToString(), 53)]);
147-
}
148121
}
149122
}
150123

151124
/// <summary>
152125
/// Backing field for <see cref="QueryTypes"/>.
153126
/// </summary>
154-
private List<QueryType> _queryTypes = new();
127+
private List<QueryType> _queryTypes = [];
155128

156129
/// <summary>
157130
/// Gets the list of available query types.
@@ -217,7 +190,7 @@ public bool IsRunning
217190
/// <summary>
218191
/// Backing field for <see cref="Results"/>.
219192
/// </summary>
220-
private ObservableCollection<DNSLookupRecordInfo> _results = new();
193+
private ObservableCollection<DNSLookupRecordInfo> _results = [];
221194

222195
/// <summary>
223196
/// Gets or sets the collection of lookup results.
@@ -351,13 +324,10 @@ public DNSLookupViewModel(IDialogCoordinator instance, Guid tabId, string host)
351324
ListSortDirection.Descending));
352325
DNSServers.SortDescriptions.Add(new SortDescription(nameof(DNSServerConnectionInfoProfile.Name),
353326
ListSortDirection.Ascending));
354-
var initialDNSServer = DNSServers.SourceCollection.Cast<DNSServerConnectionInfoProfile>()
355-
.FirstOrDefault(x => x.Name == SettingsManager.Current.DNSLookup_SelectedDNSServer.Name) ??
356-
DNSServers.SourceCollection.Cast<DNSServerConnectionInfoProfile>().First();
357-
358-
DNSServer = initialDNSServer;
359-
SelectedListProfile = initialDNSServer;
360-
DNSServerQuickInput = initialDNSServer.ToString();
327+
328+
DNSServer = string.IsNullOrEmpty(SettingsManager.Current.DNSLookup_SelectedDNSServer_v2)
329+
? SettingsManager.Current.DNSLookup_DNSServers.FirstOrDefault()?.Name
330+
: SettingsManager.Current.DNSLookup_SelectedDNSServer_v2;
361331

362332
ResultsView = CollectionViewSource.GetDefaultView(Results);
363333
ResultsView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(DNSLookupRecordInfo.NameServerAsString)));
@@ -381,7 +351,7 @@ public void OnLoaded()
381351
return;
382352

383353
if (!string.IsNullOrEmpty(Host))
384-
Query();
354+
QueryAsync();
385355

386356
_firstLoad = false;
387357
}
@@ -441,7 +411,7 @@ private bool Query_CanExecute(object parameter)
441411
private void QueryAction()
442412
{
443413
if (!IsRunning)
444-
Query();
414+
QueryAsync();
445415
}
446416

447417
/// <summary>
@@ -464,7 +434,7 @@ private void ExportAction()
464434
/// <summary>
465435
/// Performs the DNS query.
466436
/// </summary>
467-
private void Query()
437+
private async Task QueryAsync()
468438
{
469439
IsStatusMessageDisplayed = false;
470440
StatusMessage = string.Empty;
@@ -496,9 +466,67 @@ private void Query()
496466
dnsSettings.CustomDNSSuffix = SettingsManager.Current.DNSLookup_CustomDNSSuffix?.TrimStart('.');
497467
}
498468

499-
var dnsLookup = DNSServer.UseWindowsDNSServer
500-
? new DNSLookup(dnsSettings)
501-
: new DNSLookup(dnsSettings, DNSServer.Servers);
469+
470+
DNSLookup dnsLookup;
471+
472+
// Try find existing dns server profile
473+
var dnsServerProfile = SettingsManager.Current.DNSLookup_DNSServers
474+
.FirstOrDefault(x => x.Name == DNSServer);
475+
476+
// Use profile if found
477+
if (dnsServerProfile != null)
478+
{
479+
dnsLookup = dnsServerProfile.UseWindowsDNSServer
480+
? new DNSLookup(dnsSettings)
481+
: new DNSLookup(dnsSettings, dnsServerProfile.Servers);
482+
}
483+
// Otherwise try to parse custom server string
484+
else
485+
{
486+
List<ServerConnectionInfo> customDNSServers = [];
487+
488+
foreach (var customDNSServer in DNSServer.Split(';').Select(x => x.Trim()))
489+
{
490+
var customDNSServerArgs = customDNSServer.Split(':');
491+
492+
var server = customDNSServerArgs[0];
493+
var port = customDNSServerArgs.Length == 2 && int.TryParse(customDNSServerArgs[1], out var p) ? p : 53;
494+
495+
// Resolve hostname to IP address
496+
if (!IPAddress.TryParse(server, out _))
497+
{
498+
var dnsResult = await DNSClientHelper.ResolveAorAaaaAsync(server,
499+
SettingsManager.Current.Network_ResolveHostnamePreferIPv4);
500+
501+
if (dnsResult.HasError)
502+
{
503+
var dnsErrorMessage = DNSClientHelper.FormatDNSClientResultError(server, dnsResult);
504+
505+
if(!string.IsNullOrEmpty(StatusMessage))
506+
StatusMessage += Environment.NewLine;
507+
508+
StatusMessage += $"{Strings.DNSServer}: {dnsErrorMessage}";
509+
IsStatusMessageDisplayed = true;
510+
511+
continue; // Skip this server, try next one
512+
}
513+
514+
server = dnsResult.Value.ToString();
515+
}
516+
517+
customDNSServers.Add(new ServerConnectionInfo(server, port, TransportProtocol.Udp));
518+
}
519+
520+
// Check if we have any valid custom dns servers
521+
if (customDNSServers.Count == 0)
522+
{
523+
IsRunning = false;
524+
525+
return;
526+
}
527+
528+
dnsLookup = new DNSLookup(dnsSettings, customDNSServers);
529+
}
502530

503531
dnsLookup.RecordReceived += DNSLookup_RecordReceived;
504532
dnsLookup.LookupError += DNSLookup_LookupError;

Source/NETworkManager/Views/DNSLookupView.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@
7171
<TextBlock Grid.Column="4" Grid.Row="0" Text="{x:Static localization:Strings.DNSServer}"
7272
Style="{DynamicResource DefaultTextBlock}" VerticalAlignment="Center" />
7373
<ComboBox x:Name="ComboBoxDNSServers"
74-
Grid.Column="6" Grid.Row="0"
75-
ItemsSource="{Binding DNSServers}"
76-
SelectedItem="{Binding SelectedListProfile}"
77-
Text="{Binding DNSServerQuickInput, UpdateSourceTrigger=PropertyChanged}"
74+
Grid.Column="6" Grid.Row="0"
75+
ItemsSource="{Binding DNSServers}"
76+
SelectedItem="{Binding SelectedDNSServer}"
77+
Text="{Binding Path=DNSServer, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
7878
IsEditable="True"
7979
IsTextSearchEnabled="False">
8080
</ComboBox>

0 commit comments

Comments
 (0)