public async Task <DnsDetail> GetDnsDetailAsync(string hostName) { DnsDetail dnsDetail = null; try { WebRequest request = WebRequest.Create(string.Format("https://{0}", hostName)); HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync(); if (response != null && response.StatusCode.Equals(HttpStatusCode.OK)) { string serverName = response.GetResponseHeader(AppConstant.SERVER); dnsDetail = new DnsDetail { Name = hostName, WebServer = string.IsNullOrEmpty(serverName) ? string.Empty : serverName, IPAddresses = await this.GetIpAddressesAsync(hostName) }; } } catch { } return(dnsDetail); }
public async Task <List <DnsDetail> > GetDnsDetailsAsync(string[] dnsList) { List <DnsDetail> dnsDetails = new List <DnsDetail>(); var taskList = dnsList.Select(async hName => { try { if (this.ValidateDns(hName)) { hName = hName.Trim().ToLower(); var dnsDetailsCached = this.GetDnsDetailFromCache(hName); if (dnsDetailsCached != null) { dnsDetails.Add(dnsDetailsCached); } else { DnsDetail dnsDetail = await this.webRequestHandler.GetDnsDetailAsync(hName); if (dnsDetail != null) { dnsDetails.Add(dnsDetail); } } } } finally { } }); await Task.WhenAll(taskList); return(dnsDetails); }