internal static NameServerCollection Create( IEnumerable <DnsClient.DNS.RR> records, IEnumerable <DnsClient.DNS.RR> addresses = null) { // NS records from Authority Section IEnumerable <DnsClient.DNS.Records.NS> nsRecords = records.Select <DnsClient.DNS.Records.NS>(); DnsClient.DNS.Records.NS ns1 = nsRecords.FirstOrDefault(); if (ns1 == null) { return(Empty); } // There are NS RRs. NameServerCollection result = new NameServerCollection( (DnsDomain)ns1.Base.NAME, nsRecords.Select(ns => new NameServer( (DnsDomain)ns.Base.NAME, (DnsDomain)ns.NSDNAME))); // Apply address records from Additional Section (A or AAAA) if any if (addresses != null) { foreach (DnsClient.DNS.Records.Address addr in addresses.Select( rr => rr as DnsClient.DNS.Records.Address).Where(a => a != null)) { DnsDomain name = DnsDomain.Parse(addr.Base.NAME); if (result.NameServers.ContainsKey(name)) { result.NameServers[name].Addresses.Add(addr.ADDRESS); } } } return(result); }
public bool Equals(DnsDomain obj) { if (obj == null) { return(false); } return(_Domain.Equals(obj._Domain)); }
public NetworkHost(string name) { if (name == null) { throw new ArgumentNullException("name", "Value cannot be null."); } _Name = DnsDomain.Parse(name); _Addresses = new List <IPAddress>(); }
/// <summary> /// Initialize a new instance of the Resolver class using default options. /// </summary> /// <param name="domain">The domain in question</param> public DomainResolver(string domain) { if (String.IsNullOrEmpty(domain)) { throw new ArgumentNullException("domain", "String value cannot be null or empty."); } _Options = Options.Default; _Domain = (DnsDomain)domain; }
/// <summary> /// Initialize a new instance of the Resolver class using default options. /// </summary> /// <param name="domain">The domain in question</param> public DomainResolver(DnsDomain domain) { if (object.ReferenceEquals(null, domain)) { throw new ArgumentNullException("domain"); } _Options = Options.Default; _Domain = domain; }
/// <summary> /// Initialize a new instance of the Resolver class. /// </summary> /// <param name="options">Resolution options</param> /// <param name="domain">The domain in question</param> public DomainResolver(Options options, DnsDomain domain) { if (object.ReferenceEquals(null, options)) { throw new ArgumentNullException("options"); } if (object.ReferenceEquals(null, domain)) { throw new ArgumentNullException("domain"); } _Options = options; _Domain = domain; }
/// <summary> /// Initialize a new instance of the Resolver class. /// </summary> /// <param name="options">Resolution options</param> /// <param name="domain">The domain in question</param> public DomainResolver(Options options, string domain) { if (object.ReferenceEquals(null, options)) { throw new ArgumentNullException("options"); } if (String.IsNullOrEmpty(domain)) { throw new ArgumentNullException("domain", "String value cannot be null or empty."); } _Options = options; _Domain = (DnsDomain)domain; }
public NetworkHost(DnsDomain name, IEnumerable <IPAddress> addresses) { if (name == null) { throw new ArgumentNullException("name", "Value cannot be null."); } if (addresses == null) { throw new ArgumentNullException("addresses", "Value cannot be null."); } _Name = name; _Addresses = new List <IPAddress>(addresses); }
public override bool Equals(object obj) { DnsDomain n = obj as DnsDomain; if ((object)n == null) { string s = obj as string; if ((object)s == null) { return(false); } return(Equals(s)); } return(Equals(n)); }
// Internal c'tor for RootServers. // Create instances through Find(). internal NameServerCollection(DnsDomain zoneName, IEnumerable <NameServer> nameservers) { if (object.ReferenceEquals(null, zoneName)) { throw new ArgumentNullException("zoneName"); } if (object.ReferenceEquals(null, nameservers)) { throw new ArgumentNullException("nameservers"); } _ZoneName = zoneName; NameServers = nameservers.ToDictionary(s => s.Name, s => s); }
internal static NameServerCollection Find(DnsDomain domain, IEnumerable <DnsClient.DNS.RR> records, IEnumerable <DnsClient.DNS.RR> addresses) { // [RFC 1034] // 5.3.3. Algorithm // // 2. Find the best servers to ask. // // Step 2 looks for a name server to ask for the required data. The // general strategy is to look for locally-available name server RRs, // starting at SNAME, then the parent domain name of SNAME, the // grandparent, and so on toward the root. Thus if SNAME were // Mockapetris.ISI.EDU, this step would look for NS RRs for // Mockapetris.ISI.EDU, then ISI.EDU, then EDU, and then . (the root). // These NS RRs list the names of hosts for a zone at or above SNAME. Copy // the names into SLIST. // NS records from Authority Section above domain (SNAME) IEnumerable <DnsClient.DNS.Records.NS> nservers = records.Select < DnsClient.DNS.Records.NS>().Where(ns => domain.IsBelow(ns.Base.NAME)); if (!nservers.Any()) { return(Empty); } // There are relevant NS RRs. NameServerCollection result = new NameServerCollection( domain, nservers.Select(ns => new NameServer( (DnsDomain)ns.Base.NAME, (DnsDomain)ns.NSDNAME))); // Apply address records from Additional Section (A or AAAA) if any if (!object.ReferenceEquals(null, addresses)) { foreach (DnsClient.DNS.Records.Address addr in addresses.Select < DnsClient.DNS.Records.Address>()) { DnsDomain hostname = (DnsDomain)addr.Base.NAME; if (result.NameServers.ContainsKey(hostname)) { result.NameServers[hostname].Addresses.Add(addr.ADDRESS); } } } return(result); }
/// <summary> /// Randomly select one item from the collection of name servers (resolved items prefered). /// <para>The method is invalid for an empty set of name servers.</para> /// </summary> /// <returns></returns> public NameServer SelectAny() { if (IsEmpty) { throw new InvalidOperationException( "The method is invalid for an empty set of name servers."); } // At least one name server exists. NameServer selected = null; Random r = new Random((int)DateTime.Now.Ticks ^ DateTime.Now.Millisecond); // Try selecting on each name level, from highest to lowest. foreach (IGrouping <int, NameServer> nsg in Groupings) { int c = nsg.Count(), resc; if (c == 0) { continue; } // prefer resolved servers IEnumerable <NameServer> resolved = NameServers.Values.Where( ns => ns.IsResolved); if ((resc = resolved.Count()) > 0) { selected = resolved.ElementAt(r.Next(0, resc)); } else { // get any selected = nsg.ElementAt(r.Next(0, c)); } } // selected cannot be null SelectedName = selected.Name; return(selected); }
/// <summary> /// Mark one item in the collection of name servers as the selected one. /// <para>The method is invalid for an empty set of name servers.</para> /// </summary> /// <param name="selected"></param> public void SelectOne(NameServer selected) { if (IsEmpty) { throw new InvalidOperationException( "The method is invalid for an empty set of name servers."); } if (object.ReferenceEquals(null, selected)) { throw new ArgumentNullException("selected"); } try { SelectedName = NameServers[selected.Name].Name; } catch (Exception ex) { throw new ArgumentException( "The given name server was not found in the collection.", "selected", ex); } }
public static bool TryParse(string input, out DnsDomain domain) { if (object.ReferenceEquals(null, input)) { throw new ArgumentNullException("input"); } domain = null; input = input.Trim(); if (input.Equals(".")) { domain = Root; return(true); } if (input.Length == 0) { return(false); } if (input.Length > 255) { return(false); } if (input[input.Length - 1] == '.') { input = input.Substring(0, input.Length - 1); } IEnumerable <DnsLabel> labels = input.Split('.').Select(s => DnsLabel.Parse(s)); domain = new DnsDomain(labels.Reverse(), String.Join(".", labels.Select(a => (a.ToString())).ToArray()) + '.'); return(true); }
public NameServer(DnsDomain name) : base(name) { this.Zone = null; }
internal DomainResolver(DomainResolver resolver, DnsDomain domain) { _Options = resolver.Options; _Domain = domain; }
//public NameServer(string name) // : base(name) //{ // this.Zone = null; //} //public NameServer(DnsDomain name, IEnumerable<IPAddress> addresses) // : base(name, addresses) //{ //} public NameServer(DnsDomain zone, DnsDomain name) : base(name) { this.Zone = zone; }
public bool IsBelow(DnsDomain domain) { return(this._Domain.EndsWith(domain._Domain)); }
public NameServer(DnsDomain zone, DnsDomain name, IEnumerable <IPAddress> addresses) : base(name, addresses) { this.Zone = zone; }
// Empty c'tor private NameServerCollection() { _ZoneName = null; NameServers = new Dictionary <DnsDomain, NameServer>(); }