Add DNS-based domain/DC auto-discovery

This commit is contained in:
mikisoq
2026-07-29 01:56:08 -01:00
parent 3987e453c2
commit b6a57a104e
5 changed files with 335 additions and 1 deletions
+68
View File
@@ -29,6 +29,74 @@ public partial class MainWindow : Window
RefreshConnectionHelp();
RefreshActionHelp();
_ = AutoDiscoverAsync();
}
private async void Discover_Click(object? sender, RoutedEventArgs e)
{
DiscoverButton.IsEnabled = false;
SetStatus("Discovering domain and domain controller from DNS...");
try
{
var result = await DomainDiscovery.DiscoverAsync(TimeSpan.FromSeconds(10));
if (result.LdapHost is not null)
{
LdapHostBox.Text = result.LdapHost;
}
if (result.SearchBaseDn is not null)
{
SearchBaseBox.Text = result.SearchBaseDn;
}
if (result.Domain is not null)
{
var domainUpper = result.Domain.ToUpperInvariant();
var domainParts = result.Domain.Split('.');
var netbios = domainParts.Length > 0 ? domainParts[0].ToUpperInvariant() : domainUpper;
var userPlaceholder = $@"{netbios}\adminuser or adminuser@{result.Domain}";
BindUserBox.PlaceholderText = userPlaceholder;
}
SetStatus(result.Message ?? "Discovery did not return a result.");
}
catch (Exception ex)
{
SetStatus($"Discovery failed: {ex.Message}");
}
finally
{
DiscoverButton.IsEnabled = true;
}
}
private async Task AutoDiscoverAsync()
{
try
{
var result = await DomainDiscovery.DiscoverAsync(TimeSpan.FromSeconds(5));
if (result.LdapHost is not null && string.IsNullOrWhiteSpace(LdapHostBox.Text))
{
LdapHostBox.Text = result.LdapHost;
}
if (result.SearchBaseDn is not null && string.IsNullOrWhiteSpace(SearchBaseBox.Text))
{
SearchBaseBox.Text = result.SearchBaseDn;
}
if (result.LdapHost is not null || result.SearchBaseDn is not null)
{
SetStatus("Auto-discovered AD domain from DNS. Adjust if needed, then enter credentials.");
}
}
catch
{
}
}
private async void LoadCsv_Click(object? sender, RoutedEventArgs e)