diff --git a/EchoServiceApi/Controllers/DiagnosticsController.cs b/EchoServiceApi/Controllers/DiagnosticsController.cs index 43109e4..77bf3fb 100644 --- a/EchoServiceApi/Controllers/DiagnosticsController.cs +++ b/EchoServiceApi/Controllers/DiagnosticsController.cs @@ -4,6 +4,7 @@ namespace EchoServiceApi.Controllers { [Route("[controller]/[action]")] + [Route("diag/[action]")] public class DiagnosticsController : ControllerBase { public IActionResult GetInfo([FromServices] NetLah.Diagnostics.IAssemblyInfo appInfo) @@ -194,5 +195,18 @@ public async Task CertificateAsync([FromServices] CertificateVeri return Ok(VerifyResult.Failed(ex)); } } + + public async Task DnsHostEntryAsync([FromServices] DnsHostEntryVerifier dnsHostEntryVerifier, string? host) + { + try + { + var result = await dnsHostEntryVerifier.VerifyAsync(host); + return Ok(result); + } + catch (Exception ex) + { + return Ok(VerifyResult.Failed(ex)); + } + } } } diff --git a/EchoServiceApi/Program.cs b/EchoServiceApi/Program.cs index 5cff1e5..b5e2531 100644 --- a/EchoServiceApi/Program.cs +++ b/EchoServiceApi/Program.cs @@ -49,6 +49,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.Services.AddHttpClient(); builder.Services.AddHttpContextAccessor(); diff --git a/EchoServiceApi/Verifiers/DnsHostEntryVerifier.cs b/EchoServiceApi/Verifiers/DnsHostEntryVerifier.cs new file mode 100644 index 0000000..ea7d8c8 --- /dev/null +++ b/EchoServiceApi/Verifiers/DnsHostEntryVerifier.cs @@ -0,0 +1,31 @@ +using System.Net; + +namespace EchoServiceApi.Verifiers +{ + public class DnsHostEntryVerifier : BaseVerifier + { + public DnsHostEntryVerifier(IServiceProvider serviceProvider) : base(serviceProvider) { } + + public Task VerifyAsync(string? host) + { + host = string.IsNullOrWhiteSpace(host) ? string.Empty : host.Trim(); + + Logger.LogInformation("DnsHostEntryVerifier: host={host}", host); + + var ipHostEntry = Dns.GetHostEntry(host); + var addressList = ipHostEntry.AddressList?.Select(ip => ip.ToString()).ToArray(); + var result = new + { + AddressList = addressList, + ipHostEntry.HostName, + ipHostEntry.Aliases, + }; + + return Task.FromResult(new VerifySuccess + { + Message = $"DNS Lookup {host}", + Value = result + }); + } + } +}