Example #1
0
        public DnsRecord ParseSOA(string[] args)
        {
            string domainName          = args.GetRequiredValue(0);
            string primarySourceDomain = args.GetRequiredValue(1);
            string responsibleEmail    = args.GetRequiredValue(2);
            int    serialNumber        = args.GetRequiredValue <int>(3);
            int    ttl = this.ValidateTTL(args.GetOptionalValue <int>(4, 0));

            int    refresh = args.GetOptionalValue(5, 10800);
            int    retry   = args.GetOptionalValue(6, 3600);
            int    expire  = args.GetOptionalValue(7, 86400);
            int    minimum = args.GetOptionalValue(8, 10800);
            string notes   = args.GetOptionalValue(9, string.Empty);

            SOARecord record = new SOARecord(domainName
                                             , primarySourceDomain
                                             , responsibleEmail
                                             , serialNumber
                                             , refresh
                                             , retry
                                             , expire
                                             , minimum)
            {
                TTL = ttl
            };

            return(new DnsRecord(domainName, DnsStandard.RecordType.SOA, record.Serialize(), notes));
        }
Example #2
0
        /// <summary>
        /// Update the SOA record information for a domain.
        /// </summary>
        /// <param name="domain">Domain name to update record</param>
        /// <param name="SOARecord">SOA record</param>
        /// <returns>No response, check HTTP result code.</returns>
        public DomainUpdateResult SOAUpdate(string domain, SOARecord SOARecord)
        {
            var args = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>("domain", domain),
                new KeyValuePair <string, object>("nsprimary", SOARecord.nsprimary),
                new KeyValuePair <string, object>("email", SOARecord.email)
            };

            var response = ApiExecute <Record>(
                "dns/soa_update", ApiKey, args, ApiMethod.POST);

            return(new DomainUpdateResult()
            {
                ApiResponse = response.Item1
            });
        }
        private SOARecord DeserializeSoaRr(string name, int ttl, byte[] bytes, int start, out int bytesRead)
        {
            var soa = new SOARecord()
            {
                Name       = name,
                TimeToLive = ttl,
            };

            soa.MName = this.dnsSerializer.ParseQuestionName(bytes, start, out bytesRead);

            soa.RName  = this.dnsSerializer.ParseQuestionName(bytes, start + bytesRead, out var rNameBytesRead);
            bytesRead += rNameBytesRead;

            soa.Serial          = (uint)Read4BytesAsInt(bytes, bytesRead);
            soa.RefreshInterval = Read4BytesAsInt(bytes, bytesRead + 4);
            soa.RetryInterval   = Read4BytesAsInt(bytes, bytesRead + 8);
            soa.ExpireInterval  = Read4BytesAsInt(bytes, bytesRead + 12);
            soa.Minimum         = (uint)Read4BytesAsInt(bytes, bytesRead + 16);

            bytesRead += 20;

            return(soa);
        }
Example #4
0
        /// <summary>
        /// Tests equality between this SOA record and the other <paramref name="record"/>.
        /// </summary>
        /// <param name="record">The other record.</param>
        /// <returns><c>true</c> if the RRs are equal, <c>false</c> otherwise.</returns>
        public override bool Equals(DnsResourceRecord record)
        {
            if (!base.Equals(record))
            {
                return(false);
            }

            SOARecord soaRecord = record as SOARecord;

            if (soaRecord == null)
            {
                return(false);
            }

            return(
                DnsStandard.Equals(m_mname, soaRecord.m_mname) &&
                DnsStandard.Equals(m_rname, soaRecord.m_rname) &&
                this.SerialNumber == soaRecord.SerialNumber &&
                this.Refresh == soaRecord.Refresh &&
                this.Retry == soaRecord.Retry &&
                this.Expire == soaRecord.Expire &&
                this.Minimum == soaRecord.Minimum
                );
        }
        public void CreateDnsResourceRecords(string domain)
        {
            DnsBuffer buff = new DnsBuffer();

            byte[]        bytes;
            AddressRecord arec = new AddressRecord(domain
                                                   , "127.0.0.1")
            {
                TTL = 1000
            };

            arec.Serialize(buff);

            string path = Path.Combine(DNSRECORDSEPATH, string.Format("aname.{0}.bin", domain));

            Console.WriteLine("Creating {0}", path);

            using (FileStream s = new FileStream(path, FileMode.OpenOrCreate))
            {
                s.Write(buff.Buffer
                        , 0
                        , buff.Buffer.Length);
                s.Close();
            }


            //----------------------------------------------------------------------------------------------------
            //---read the stream from the bytes
            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                Console.WriteLine("checking [{0}]", path);
                bytes = new BinaryReader(fs).ReadBytes((int)new FileInfo(path).Length);
                DnsBufferReader rdr = new DnsBufferReader(bytes, 0, bytes.Length);
                arec = (AddressRecord)DnsResourceRecord.Deserialize(ref rdr);
            }
            Console.WriteLine(arec.IPAddress);
            Console.WriteLine(arec.TTL);
            Console.WriteLine(arec.Name);
            //----------------------------------------------------------------------------------------------------------------
            SOARecord soa = new SOARecord(domain
                                          , domain + ".dom"
                                          , "somebody"
                                          , 1
                                          , 2
                                          , 3
                                          , 4
                                          , 5)
            {
                TTL = 2000
            };

            buff = new DnsBuffer();
            soa.Serialize(buff);

            path = Path.Combine(DNSRECORDSEPATH, string.Format("soa.{0}.bin", domain));
            Console.WriteLine("Creating {0}", path);

            using (FileStream s = new FileStream(path, FileMode.OpenOrCreate))
            {
                s.Write(buff.Buffer
                        , 0
                        , buff.Buffer.Length);
                s.Close();
            }

            //----------------------------------------------------------------------------------------------------
            //---read the stream from the bytes
            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                Console.WriteLine("checking [{0}]", path);
                bytes = new BinaryReader(fs).ReadBytes((int)new FileInfo(path).Length);
                DnsBufferReader rdr = new DnsBufferReader(bytes, 0, bytes.Length);
                soa = (SOARecord)DnsResourceRecord.Deserialize(ref rdr);
            }
            Console.WriteLine(soa.ResponsibleName);
            Console.WriteLine(soa.SerialNumber);
            Console.WriteLine(soa.Retry);
            Console.WriteLine(soa.Refresh);
            Console.WriteLine(soa.Expire);
            Console.WriteLine(soa.Minimum);
            Console.WriteLine(soa.TTL);
            Console.WriteLine(soa.Name);
            //----------------------------------------------------------------------------------------------------------------
            MXRecord mx = new MXRecord(domain
                                       , string.Format("mx.{0}", domain)
                                       , 1)
            {
                TTL = 2000
            };

            buff = new DnsBuffer();
            mx.Serialize(buff);

            path = Path.Combine(DNSRECORDSEPATH, string.Format("mx.{0}.bin", domain));
            Console.WriteLine("Creating {0}", path);

            using (FileStream s = new FileStream(path, FileMode.OpenOrCreate))
            {
                s.Write(buff.Buffer
                        , 0
                        , buff.Buffer.Length);
                s.Close();
            }

            //----------------------------------------------------------------------------------------------------
            //---read the stream from the bytes
            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                Console.WriteLine("checking [{0}]", path);
                bytes = new BinaryReader(fs).ReadBytes((int)new FileInfo(path).Length);
                DnsBufferReader rdr = new DnsBufferReader(bytes, 0, bytes.Length);
                mx = (MXRecord)DnsResourceRecord.Deserialize(ref rdr);
            }
            Console.WriteLine(mx.Exchange);
            Console.WriteLine(mx.Name);
            Console.WriteLine(mx.Preference);

            //----------------------------------------------------------------------------------------------------------------
            //---create the cert on the fly
            CertRecord cert = new CertRecord(new DnsX509Cert(CreateNamedKeyCertificate(new CertData(domain
                                                                                                    , domain
                                                                                                    , string.Format("CN={0}", domain)
                                                                                                    , ""))))
            {
                TTL = 2000
            };

            buff = new DnsBuffer();
            cert.Serialize(buff);

            path = Path.Combine(DNSRECORDSEPATH, string.Format("cert.{0}.bin", domain));
            Console.WriteLine("Creating {0}", path);

            using (FileStream s = new FileStream(path, FileMode.OpenOrCreate))
            {
                s.Write(buff.Buffer
                        , 0
                        , buff.Buffer.Length);
                s.Close();
            }

            //----------------------------------------------------------------------------------------------------
            //---read the stream from the bytes
            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                Console.WriteLine("checking [{0}]", path);
                bytes = new BinaryReader(fs).ReadBytes((int)new FileInfo(path).Length);
                DnsBufferReader rdr = new DnsBufferReader(bytes, 0, bytes.Length);
                cert = (CertRecord)DnsResourceRecord.Deserialize(ref rdr);
            }
            Console.WriteLine(cert.Name);
            Console.WriteLine(cert.Cert.Certificate.NotBefore);
            Console.WriteLine(cert.Cert.Certificate.NotAfter);
        }