예제 #1
0
        public static string HttpsDnsHostAddresses(string serverIpStr, bool googleDNS = false)
        {
            string dnsStr;

            if (googleDNS)
            {
                dnsStr = new WebClient().DownloadString(
                    $"https://dnsp.milione.cc/resolve/?name={serverIpStr}&type=A");
            }

            else
            {
                dnsStr = new WebClient().DownloadString(
                    $"https://dns.cloudflare.com/dns-query?ct=application/dns-json&name={serverIpStr}&type=A");
            }

            JsonValue dnsAnswerJson = Json.Parse(dnsStr).AsObjectGet("Answer");
            string    ipAnswerStr   = dnsAnswerJson.AsArrayGet(0).AsObjectGetString("data");

            return(IsIP(ipAnswerStr) ? ipAnswerStr : HttpsDnsHostAddresses(ipAnswerStr));
        }