Ejemplo n.º 1
0
    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();
    }
Ejemplo n.º 2
0
    public DnsResponse(DnsQueryParamBase query, IEnumerable <string> fqdnList)
    {
        this.Query = query;

        this.IPAddressList = new List <IPAddress>();

        this.FqdnList = fqdnList.ToList();
    }
Ejemplo n.º 3
0
    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>();
    }
Ejemplo n.º 4
0
 protected abstract Task <DnsResponse> QueryDnsImplAsync(DnsQueryParamBase param, CancellationToken cancel);