public IPEndPoint[] GetEndpointsValue() { if (ServerArg.HasValue()) { var values = ServerArg.Values.Select(p => p.Split('#').ToArray()); var result = new List <IPEndPoint>(); foreach (var serverPair in values) { var server = serverPair[0]; var port = serverPair.Length > 1 ? int.Parse(serverPair[1]) : 53; IPAddress ip; if (!IPAddress.TryParse(server, out ip)) { var lookup = new LookupClient(); var lResult = lookup.QueryAsync(server, QueryType.A).Result; ip = lResult.Answers.OfType <ARecord>().FirstOrDefault()?.Address; } if (ip == null) { throw new ArgumentException($"Invalid address or hostname '{server}'."); } result.Add(new IPEndPoint(ip, port)); } return(result.ToArray()); } else { return(NameServer.ResolveNameServers().ToArray()); } }
static STUNDns() { var nameServers = NameServer.ResolveNameServers(skipIPv6SiteLocal: true, fallbackToGooglePublicDns: true); LookupClientOptions clientOptions = new LookupClientOptions(nameServers.ToArray()) { Retries = DNS_RETRIES_PER_SERVER, Timeout = TimeSpan.FromSeconds(DNS_TIMEOUT_SECONDS), UseCache = true, UseTcpFallback = false }; _lookupClient = new LookupClient(clientOptions); }
static SIPDns() { var nameServers = NameServer.ResolveNameServers(skipIPv6SiteLocal: true, fallbackToGooglePublicDns: true); LookupClientOptions clientOptions = new LookupClientOptions(nameServers.ToArray()) { Retries = DNS_RETRIES_PER_SERVER, Timeout = TimeSpan.FromSeconds(DNS_TIMEOUT_SECONDS), UseCache = true, // TODO: Re-enable when DnsClient adds cache querying. //UseCacheForFailures = true, }; _lookupClient = new LookupClient(clientOptions); }
static SIPDns() { var nameServers = NameServer.ResolveNameServers(skipIPv6SiteLocal: true, fallbackToGooglePublicDns: true); LookupClientOptions clientOptions = new LookupClientOptions(nameServers.ToArray()) { Retries = DNS_RETRIES_PER_SERVER, Timeout = TimeSpan.FromSeconds(DNS_TIMEOUT_SECONDS), UseCache = true, CacheFailedResults = true, FailedResultsCacheDuration = TimeSpan.FromSeconds(CACHE_FAILED_RESULTS_DURATION) }; _lookupClient = new LookupClient(clientOptions); }
private List <IPEndPoint> GetDnsServer() { List <IPEndPoint> dnsServers = new List <IPEndPoint>(); if (UseCustomDNSServer) { foreach (var dnsServer in CustomDNSServer.Servers) { dnsServers.Add(new IPEndPoint(IPAddress.Parse(dnsServer), CustomDNSServer.Port)); } } else { foreach (var dnsServer in NameServer.ResolveNameServers(true, false)) { dnsServers.Add(dnsServer); } } return(dnsServers); }
public IReadOnlyCollection <IPEndPoint> NameServers() { return(NameServer.ResolveNameServers(true, false).ToArray()); }
public IReadOnlyCollection <IPEndPoint> NameServers() { return(NameServer.ResolveNameServers(true, false).Select(s => new IPEndPoint(IPAddress.Parse(s.Address), s.Port)).ToArray()); }