protected override async Task <DnsResponse> QueryDnsImplAsync(DnsQueryParamBase param, CancellationToken cancel) { switch (param) { case DnsGetIpQueryParam getIpQuery: if (IPAddress.TryParse(getIpQuery.Hostname, out IPAddress? ip)) { return(new DnsResponse(param, ip._SingleArray())); } else { return(new DnsResponse(param, await PalDns.GetHostAddressesAsync(getIpQuery.Hostname, getIpQuery.Timeout, cancel))); } case DnsGetFqdnQueryParam getFqdnQuery: var res = await PalDns.GetHostEntryAsync(getFqdnQuery.Ip._UnmapIPv4(), getFqdnQuery.Timeout, cancel); List <string> hostNameList = new List <string>(); hostNameList.Add(res.HostName); res.Aliases._DoForEach(x => hostNameList.Add(x)); hostNameList.Distinct(); return(new DnsResponse(param, hostNameList)); } throw new NotImplementedException(); }
public DnsResponse(DnsQueryParamBase query, IEnumerable <string> fqdnList) { this.Query = query; this.IPAddressList = new List <IPAddress>(); this.FqdnList = fqdnList.ToList(); }
public DnsResponse(DnsQueryParamBase query, IEnumerable <IPAddress> addressList) { this.Query = query; IEnumerable <IPAddress> filtered = addressList; if (this.Query.Options.Bit(DnsQueryOptions.IPv4Only)) { filtered = filtered.Where(x => x.AddressFamily == AddressFamily.InterNetwork); } if (this.Query.Options.Bit(DnsQueryOptions.IPv6Only)) { filtered = filtered.Where(x => x.AddressFamily == AddressFamily.InterNetworkV6); } this.IPAddressList = new List <IPAddress>(filtered); this.FqdnList = new List <string>(); }
protected abstract Task <DnsResponse> QueryDnsImplAsync(DnsQueryParamBase param, CancellationToken cancel);