/// <summary> /// Convenience method resolving and returning NS RRs. /// </summary> /// <param name="domain"> /// The domain name to resolve. /// </param> /// <returns> /// An enumeration of NS Records. See <see cref="NSRecord"/> /// </returns> public IEnumerable <NSRecord> ResolveNS(string domain) { DnsResponse response = this.Resolve(DnsRequest.CreateNS(domain)); if (response == null || !response.HasNameServerRecords) { return(null); } return(response.AnswerRecords.NS); }
/// <summary> /// Resolves all the name server names for a given domain /// </summary> /// <param name="domain"></param> /// <returns>An enumeration of name server names</returns> public IEnumerable <string> GetNameServerNames(string domain) { DnsResponse response = this.Resolve(DnsRequest.CreateNS(domain)); if (response == null) { yield break; } IEnumerable <DnsResourceRecord> nsRecords = null; if (response.HasAnswerRecords) { nsRecords = response.AnswerRecords; } else if (response.HasNameServerRecords) { nsRecords = response.NameServerRecords; } if (nsRecords == null) { yield break; } string serverName = null; foreach (DnsResourceRecord record in nsRecords) { serverName = null; switch (record.Type) { default: break; case DnsStandard.RecordType.NS: serverName = ((NSRecord)record).NameServer; break; case DnsStandard.RecordType.SOA: serverName = ((SOARecord)record).DomainName; break; } if (serverName != null) { yield return(serverName); } } }