Beispiel #1
0
 /// <summary>
 /// Prints a SOA RR
 /// </summary>
 /// <param name="soa">The RR to print</param>
 public void Print(SOARecord soa)
 {
     this.Print("DomainName", soa.Name);
     this.Print("PrimarySourceDomain", soa.DomainName);
     this.Print("Refresh", soa.Refresh);
     this.Print("Retry", soa.Retry);
     this.Print("Expire", soa.Expire);
     this.Print("Minimum", soa.Minimum);
 }
Beispiel #2
0
        /// <summary>
        /// Factory for DnsResourceRecord objects
        /// </summary>
        /// <param name="recordType"></param>
        /// <returns></returns>
        public static DnsResourceRecord CreateRecordObject(DnsStandard.RecordType recordType)
        {
            DnsResourceRecord record;

            switch (recordType)
            {
            default:
                record = new RawRecord();
                break;

            case DnsStandard.RecordType.ANAME:
                record = new AddressRecord();
                break;

            case DnsStandard.RecordType.NS:
                record = new NSRecord();
                break;

            case DnsStandard.RecordType.CNAME:
                record = new CNameRecord();
                break;

            case DnsStandard.RecordType.SOA:
                record = new SOARecord();
                break;

            case DnsStandard.RecordType.TXT:
                record = new TextRecord();
                break;

            case DnsStandard.RecordType.MX:
                record = new MXRecord();
                break;

            case DnsStandard.RecordType.PTR:
                record = new PtrRecord();
                break;

            case DnsStandard.RecordType.CERT:
                record = new CertRecord();
                break;

            case DnsStandard.RecordType.SRV:
                record = new SRVRecord();
                break;
            }

            return(record);
        }
Beispiel #3
0
        /// <summary>
        /// Factory for DnsResourceRecord objects
        /// </summary>
        /// <param name="recordType"></param>
        /// <returns></returns>
        public static DnsResourceRecord CreateRecordObject(DnsStandard.RecordType recordType)
        {
            DnsResourceRecord record;
            switch (recordType)
            {
                default:
                    record = new RawRecord();
                    break;

                case DnsStandard.RecordType.ANAME:
                    record = new AddressRecord();
                    break;

                case DnsStandard.RecordType.NS:
                    record = new NSRecord();
                    break;

                case DnsStandard.RecordType.CNAME:
                    record = new CNameRecord();
                    break;

                case DnsStandard.RecordType.SOA:
                    record = new SOARecord();
                    break;

                case DnsStandard.RecordType.TXT:
                    record = new TextRecord();
                    break;

                case DnsStandard.RecordType.MX:
                    record = new MXRecord();
                    break;
                
                case DnsStandard.RecordType.PTR:
                    record = new PtrRecord();
                    break;
                    
                case DnsStandard.RecordType.CERT:
                    record = new CertRecord();
                    break;
                
                case DnsStandard.RecordType.SRV:
                    record = new SRVRecord();
                    break;
            }
            
            return record;
        }
        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);
        }