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)); }
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); }