public static byte[] GetDataByMWebClient(string url, bool proxyEnable = false, IWebProxy wProxy = null, bool allowRedirect = true) { MWebClient mWebClient = new MWebClient { Headers = { ["User-Agent"] = "AuroraDNSC/0.1" } }; mWebClient.AllowAutoRedirect = allowRedirect; mWebClient.Proxy = proxyEnable ? wProxy : new WebProxy(); return(mWebClient.DownloadData(url)); }
public static byte[] GetDataByMWebClient(string url, bool proxyEnable = false, IWebProxy wProxy = null) { MWebClient mWebClient = new MWebClient { Headers = { ["User-Agent"] = "AuroraDNSC/0.1" } }; //if (bool) webClient.AllowAutoRedirect = false; if (proxyEnable) { mWebClient.Proxy = wProxy; } return(mWebClient.DownloadData(url)); }
private static (List <DnsRecordBase> list, ReturnCode statusCode) ResolveOverHttpsByDnsMsg(string clientIpAddress, string domainName, string dohUrl, bool proxyEnable = false, IWebProxy wProxy = null, RecordType type = RecordType.A) { DnsMessage dnsMsg; MWebClient mWebClient = new MWebClient { Headers = { ["User-Agent"] = "AuroraDNSC/0.1" } }; if (proxyEnable) { mWebClient.Proxy = wProxy; } var dnsBase64String = Convert.ToBase64String(MyDnsSend.GetQuestionData(domainName.TrimEnd('.'), type)).TrimEnd('=') .Replace('+', '-').Replace('/', '_'); try { var dnsDataBytes = mWebClient.DownloadData( $"{dohUrl}?ct=application/dns-message&dns={dnsBase64String}&edns_client_subnet={clientIpAddress}"); dnsMsg = DnsMessage.Parse(dnsDataBytes); } catch (WebException e) { HttpWebResponse response = (HttpWebResponse)e.Response; try { BackgroundLog($@"| - Catch WebException : {Convert.ToInt32(response.StatusCode)} {response.StatusCode} | {domainName} | {dohUrl} | {dnsBase64String}"); if (response.StatusCode == HttpStatusCode.BadRequest) { DnsSettings.DnsMsgEnable = false; return(ResolveOverHttpsByDnsJson(clientIpAddress, domainName, DnsSettings.SecondHttpsDnsUrl, proxyEnable, wProxy, type)); } } catch (Exception exception) { BackgroundLog($@"| - Catch WebException : {exception.Message} | {domainName} | {dohUrl} | {dnsBase64String}"); } if (dohUrl != DnsSettings.HttpsDnsUrl) { return(new List <DnsRecordBase>(), ReturnCode.ServerFailure); } BackgroundLog($@"| -- SecondDoH : {DnsSettings.SecondHttpsDnsUrl}"); return(ResolveOverHttpsByDnsMsg(clientIpAddress, domainName, DnsSettings.SecondHttpsDnsUrl, proxyEnable, wProxy, type)); } return(dnsMsg.AnswerRecords, dnsMsg.ReturnCode); }