using System; using System.Net; using System.Text; namespace Unosquare.Swan.Networking { /// /// Represents a DNS record entry. /// public class DnsRecord { /// /// Initializes a new instance of the class. /// /// The record. internal DnsRecord(DnsClient.IDnsResourceRecord record) : this() { this.Name = record.Name.ToString(); this.Type = record.Type; this.Class = record.Class; this.TimeToLive = record.TimeToLive; this.Data = record.Data; // PTR this.PointerDomainName = (record as DnsClient.DnsPointerResourceRecord)?.PointerDomainName?.ToString(); // A this.IPAddress = (record as DnsClient.DnsIPAddressResourceRecord)?.IPAddress; // NS this.NameServerDomainName = (record as DnsClient.DnsNameServerResourceRecord)?.NSDomainName?.ToString(); // CNAME this.CanonicalDomainName = (record as DnsClient.DnsCanonicalNameResourceRecord)?.CanonicalDomainName.ToString(); // MX this.MailExchangerDomainName = (record as DnsClient.DnsMailExchangeResourceRecord)?.ExchangeDomainName.ToString(); this.MailExchangerPreference = (record as DnsClient.DnsMailExchangeResourceRecord)?.Preference; // SOA this.SoaMasterDomainName = (record as DnsClient.DnsStartOfAuthorityResourceRecord)?.MasterDomainName.ToString(); this.SoaResponsibleDomainName = (record as DnsClient.DnsStartOfAuthorityResourceRecord)?.ResponsibleDomainName.ToString(); this.SoaSerialNumber = (record as DnsClient.DnsStartOfAuthorityResourceRecord)?.SerialNumber; this.SoaRefreshInterval = (record as DnsClient.DnsStartOfAuthorityResourceRecord)?.RefreshInterval; this.SoaRetryInterval = (record as DnsClient.DnsStartOfAuthorityResourceRecord)?.RetryInterval; this.SoaExpireInterval = (record as DnsClient.DnsStartOfAuthorityResourceRecord)?.ExpireInterval; this.SoaMinimumTimeToLive = (record as DnsClient.DnsStartOfAuthorityResourceRecord)?.MinimumTimeToLive; } private DnsRecord() { // placeholder } /// /// Gets the name. /// /// /// The name. /// public String Name { get; } /// /// Gets the type. /// /// /// The type. /// public DnsRecordType Type { get; } /// /// Gets the class. /// /// /// The class. /// public DnsRecordClass Class { get; } /// /// Gets the time to live. /// /// /// The time to live. /// public TimeSpan TimeToLive { get; } /// /// Gets the raw data of the record. /// /// /// The data. /// public Byte[] Data { get; } /// /// Gets the data text bytes in ASCII encoding. /// /// /// The data text. /// public String DataText => this.Data == null ? String.Empty : Encoding.ASCII.GetString(this.Data); /// /// Gets the name of the pointer domain. /// /// /// The name of the pointer domain. /// public String PointerDomainName { get; } /// /// Gets the ip address. /// /// /// The ip address. /// public IPAddress IPAddress { get; } /// /// Gets the name of the name server domain. /// /// /// The name of the name server domain. /// public String NameServerDomainName { get; } /// /// Gets the name of the canonical domain. /// /// /// The name of the canonical domain. /// public String CanonicalDomainName { get; } /// /// Gets the mail exchanger preference. /// /// /// The mail exchanger preference. /// public Int32? MailExchangerPreference { get; } /// /// Gets the name of the mail exchanger domain. /// /// /// The name of the mail exchanger domain. /// public String MailExchangerDomainName { get; } /// /// Gets the name of the soa master domain. /// /// /// The name of the soa master domain. /// public String SoaMasterDomainName { get; } /// /// Gets the name of the soa responsible domain. /// /// /// The name of the soa responsible domain. /// public String SoaResponsibleDomainName { get; } /// /// Gets the soa serial number. /// /// /// The soa serial number. /// public Int64? SoaSerialNumber { get; } /// /// Gets the soa refresh interval. /// /// /// The soa refresh interval. /// public TimeSpan? SoaRefreshInterval { get; } /// /// Gets the soa retry interval. /// /// /// The soa retry interval. /// public TimeSpan? SoaRetryInterval { get; } /// /// Gets the soa expire interval. /// /// /// The soa expire interval. /// public TimeSpan? SoaExpireInterval { get; } /// /// Gets the soa minimum time to live. /// /// /// The soa minimum time to live. /// public TimeSpan? SoaMinimumTimeToLive { get; } } }