Add DNS-based domain/DC auto-discovery
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user