/// <summary> /// Initialises a new instance of the <see cref="StartOfAuthority"/> class. /// </summary> /// <param name="otherRecord"> /// The other record. /// </param> public StartOfAuthority(ResourceRecord otherRecord) { this.RecordType = otherRecord.RecordType; this.Zone = otherRecord.Zone; this.ZonePath = otherRecord.ZonePath; this.RecordValue = otherRecord.RecordValue; }
/// <summary> /// Parses the device-specific totals of each resource type. /// </summary> /// <param name="reportPath">path to PAR report</param> /// <param name="rec">resource record to receive the parsed information</param> public static void ParseTotals(string reportPath, ResourceRecord rec) { using (var rd = new StreamReader(reportPath)) { while (!rd.EndOfStream) { string line = rd.ReadLine(); EDeviceResource res; int count, total; if (MatchLine(line, out res, out count, out total)) { rec.AssignResource(res, total); } } rd.Close(); } }
/// <summary> /// /// </summary> /// <param name="info">The information.</param> /// <param name="algorithm">The algorithm.</param> /// <param name="fingerprintType">The fingerprint type.</param> /// <param name="fingerprint">The fingerprint.</param> public SshfpRecord(ResourceRecord info, SshfpAlgorithm algorithm, SshfpFingerprintType fingerprintType, string fingerprint) : base(info) { Algorithm = algorithm; FingerprintType = fingerprintType; Fingerprint = fingerprint; }
public AfsDbRecord ReadResourceRecord( ResourceRecord info, DnsDatagramReader reader) => new AfsDbRecord( info, (AfsType)reader.ReadUInt16NetworkOrder(), reader.ReadDnsName());
/// <summary> /// Initializes a new instance of the <see cref="MrRecord"/> class. /// </summary> /// <param name="info">The information.</param> /// <param name="name">The domain name.</param> /// <exception cref="System.ArgumentNullException">If <paramref name="name"/> or <paramref name="info"/> is null.</exception> public MrRecord(ResourceRecord info, DnsString name) : base(info) { NewName = name ?? throw new ArgumentNullException(nameof(name)); }
public ResourceRecordModel() { this._record = null; this.NewRecord = true; }
public static void ToRecord(Resource res, ResourceRecord rec) { ObjectCopy.Copy(res, rec); }
public static DateTime GetExpareTime(this ResourceRecord rec) { return(rec.CreationTime.Add(rec.TTL)); }
/// <summary> /// Initializes a new instance of the <see cref="HInfoRecord"/> class. /// </summary> /// <param name="info">The information.</param> /// <param name="cpu">The cpu.</param> /// <param name="os">The os.</param> /// <exception cref="System.ArgumentNullException">If <paramref name="info"/> is null.</exception> public HInfoRecord(ResourceRecord info, string cpu, string os) : base(info) { Cpu = cpu; Os = os; }
public static void UpdateCache(ResourceRecord rec) { var dev = new DeviceRecordsDevice(); dev.name = rec.Device.ToString(); dev.timestamp = DateTime.Now; var rlist = new List<DeviceRecordsDeviceResource>(); rlist.Add(new DeviceRecordsDeviceResource() { name = PropEnum.ToString(EDeviceResource.SliceRegisters, EPropAssoc.PARReport), amount = rec.SliceRegisters }); rlist.Add(new DeviceRecordsDeviceResource() { name = PropEnum.ToString(EDeviceResource.SliceLUTs, EPropAssoc.PARReport), amount = rec.SliceLUTs }); rlist.Add(new DeviceRecordsDeviceResource() { name = PropEnum.ToString(EDeviceResource.OccupiedSlices, EPropAssoc.PARReport), amount = rec.OccupiedSlices }); rlist.Add(new DeviceRecordsDeviceResource() { name = PropEnum.ToString(EDeviceResource.RAMB18s, EPropAssoc.PARReport), amount = rec.RAMB18s }); rlist.Add(new DeviceRecordsDeviceResource() { name = PropEnum.ToString(EDeviceResource.RAMB36s, EPropAssoc.PARReport), amount = rec.RAMB36s }); rlist.Add(new DeviceRecordsDeviceResource() { name = PropEnum.ToString(EDeviceResource.DSP48E1s, EPropAssoc.PARReport), amount = rec.DSP48E1s }); dev.providedResources = rlist.ToArray(); var drecs = DeviceRecords; int idx = Array.FindIndex(drecs.device, d => d.name == dev.name); if (idx < 0) drecs.device = drecs.device.Concat(new DeviceRecordsDevice[] { dev }).ToArray(); else drecs.device[idx] = dev; using (var wr = new StreamWriter(DeviceCachePath)) { DeviceDataSerializer.Serialize(wr, drecs); wr.Close(); } }
public static ResourceRecord QueryDeviceResources(EDevice device) { var recs = DeviceRecords; string devName = device.ToString(); var hit = recs.device .Where(d => d.name == devName) .FirstOrDefault(); if (hit == null) return null; var result = new ResourceRecord() { Device = device }; foreach (var resrec in hit.providedResources) { EDeviceResource res; if (DeviceResources.ResolveResourceType(resrec.name, out res)) { result.AssignResource(res, resrec.amount); } } return result; }
public ARecord ReadResourceRecord( ResourceRecord info, DnsDatagramReader reader) => new ARecord(info, reader.ReadIpAddress());
/// <summary> /// Parses a packet from incomming data. /// </summary> /// <param name="data">Byte array containing the incomming data.</param> /// <returns>A parsed Packet.</returns> public static Packet Parse(byte[] data) { Packet packet = new Packet(); packet.Header = Header.Parse(data); int offset = packet.Header.ByteSize; if (packet.Header.QdCount > 0) { packet.QuestionEntries = new QuestionName[packet.Header.QdCount]; for (int i = 0; i < packet.Header.QdCount; i++) { packet.QuestionEntries[i] = QuestionName.Parse(data, ref offset); } } else { packet.QuestionEntries = null; } if (packet.Header.AnCount > 0) { packet.AnswerResourceRecords = new ResourceRecord[packet.Header.AnCount]; for (int i = 0; i < packet.Header.AnCount; i++) { packet.AnswerResourceRecords[i] = ResourceRecord.Parse(data, ref offset); } } else { packet.AnswerResourceRecords = null; } if (packet.Header.NsCount > 0) { packet.AuthorityResourceRecords = new ResourceRecord[packet.Header.NsCount]; for (int i = 0; i < packet.Header.NsCount; i++) { packet.AuthorityResourceRecords[i] = ResourceRecord.Parse(data, ref offset); } } else { packet.AuthorityResourceRecords = null; } if (packet.Header.ArCount > 0) { packet.AdditionalResourceRecords = new ResourceRecord[packet.Header.ArCount]; for (int i = 0; i < packet.Header.ArCount; i++) { packet.AdditionalResourceRecords[i] = ResourceRecord.Parse(data, ref offset); } } else { packet.AdditionalResourceRecords = null; } return(packet); }
internal Resource(AppFactory factory, ResourceRecord record) { this.factory = factory; this.record = record ?? new ResourceRecord(); ID = new EntityID(this.record.ID); }
internal DnsPacket(Frame parentFrame, int packetStartIndex, int packetEndIndex, bool lengthPrefix = false) : base(parentFrame, packetStartIndex, packetEndIndex, "DNS") { if (lengthPrefix) //Typically when parsing DNS over TCP { ushort packetLength = Utils.ByteConverter.ToUInt16(parentFrame.Data, packetStartIndex); packetStartIndex += 2; base.PacketStartIndex += 2; base.PacketEndIndex = Math.Min(base.PacketEndIndex, base.PacketStartIndex + packetLength - 1); } //header this.transactionID = Utils.ByteConverter.ToUInt16(parentFrame.Data, packetStartIndex); this.headerFlags = new HeaderFlags(Utils.ByteConverter.ToUInt16(parentFrame.Data, packetStartIndex + 2)); if (!this.ParentFrame.QuickParse) { if (this.headerFlags.Response) { this.Attributes.Add("Type", "Response"); } else { this.Attributes.Add("Type", "Request"); } if (this.headerFlags.OperationCode == (byte)HeaderFlags.OperationCodes.Query) { this.Attributes.Add("Operation", "Standard Query"); } else if (this.headerFlags.OperationCode == (byte)HeaderFlags.OperationCodes.InverseQuery) { this.Attributes.Add("Operation", "Inverse Query"); } } //NetworkMiner currently does not handle Dynamic Update (operation code 5) if (this.headerFlags.OperationCode < 5) { this.questionCount = Utils.ByteConverter.ToUInt16(parentFrame.Data, packetStartIndex + 4); if (this.questionCount > 64) { throw new Exception("Too many questions in DNS: " + this.questionCount);//this is probably not DNS } this.answerCount = Utils.ByteConverter.ToUInt16(parentFrame.Data, packetStartIndex + 6); this.answerRecords = new ResourceRecord[answerCount]; if (questionCount > 0) { //this.questionSectionByteCount=0; //List<NameLabel> nameLabelList=GetNameLabelList(parentFrame.Data, packetStartIndex+12); int typeStartOffset; List <NameLabel> nameLabelList = GetNameLabelList(parentFrame.Data, packetStartIndex, 12, out typeStartOffset); /* * foreach(NameLabel label in nameLabelList) { * questionSectionByteCount+=label.LabelByteCount+1; * } * */ //this.questionSectionByteCount++;//add the last 0x00 terminator this.questionSectionByteCount = typeStartOffset - 12; //we have now decoded the name! this.questionNameDecoded = new string[nameLabelList.Count]; for (int i = 0; i < nameLabelList.Count; i++) { this.questionNameDecoded[i] = nameLabelList[i].ToString(); } //this.questionType=ByteConverter.ToUInt16(parentFrame.Data, packetStartIndex+12+questionSectionByteCount); this.questionType = Utils.ByteConverter.ToUInt16(parentFrame.Data, packetStartIndex + typeStartOffset); questionSectionByteCount += 2; //this.questionClass=ByteConverter.ToUInt16(parentFrame.Data, packetStartIndex+12+questionSectionByteCount); this.questionClass = Utils.ByteConverter.ToUInt16(parentFrame.Data, packetStartIndex + typeStartOffset + 2); questionSectionByteCount += 2; } else { this.questionSectionByteCount = 0; this.questionNameDecoded = null; } //ANSWER RESOURCE RECORDS int packetPositionIndex = packetStartIndex + 12 + questionSectionByteCount; for (int i = 0; i < answerRecords.Length; i++) { //ResourceRecord answerRecord in answerRecords) { answerRecords[i] = new ResourceRecord(this, packetPositionIndex); packetPositionIndex += answerRecords[i].ByteCount; //decodedName.ToString(); if (!this.ParentFrame.QuickParse) { if (answerRecords[i].Type == (ushort)RRTypes.HostAddress) { if (answerRecords[i].IP != null) { this.Attributes.Add("IP", answerRecords[i].IP.ToString()); } if (answerRecords[i].DNS != null) { this.Attributes.Add("DNS", answerRecords[i].DNS); } } } } //AUTHORITY RESOURCE RECORDS //I'll just skip the rest of the packet! } }
public MgRecord ReadResourceRecord( ResourceRecord info, DnsDatagramReader reader) => new MgRecord(info, reader.ReadDnsName());
public void TestConvertInterface() { var response = new byte[] { 41, 163, 133, 0, 0, 1, 0, 3, 0, 7, 0, 7, 5, 121, 97, 104, 111, 111, 3, 99, 111, 109, 0, 0, 15, 0, 1, 192, 12, 0, 15, 0, 1, 0, 0, 7, 8, 0, 25, 0, 1, 4, 109, 116, 97, 55, 3, 97, 109, 48, 8, 121, 97, 104, 111, 111, 100, 110, 115, 3, 110, 101, 116, 0, 192, 12, 0, 15, 0, 1, 0, 0, 7, 8, 0, 9, 0, 1, 4, 109, 116, 97, 54, 192, 46, 192, 12, 0, 15, 0, 1, 0, 0, 7, 8, 0, 9, 0, 1, 4, 109, 116, 97, 53, 192, 46, 192, 12, 0, 2, 0, 1, 0, 2, 163, 0, 0, 6, 3, 110, 115, 50, 192, 12, 192, 12, 0, 2, 0, 1, 0, 2, 163, 0, 0, 6, 3, 110, 115, 51, 192, 12, 192, 12, 0, 2, 0, 1, 0, 2, 163, 0, 0, 6, 3, 110, 115, 52, 192, 12, 192, 12, 0, 2, 0, 1, 0, 2, 163, 0, 0, 6, 3, 110, 115, 49, 192, 12, 192, 12, 0, 2, 0, 1, 0, 2, 163, 0, 0, 6, 3, 110, 115, 54, 192, 12, 192, 12, 0, 2, 0, 1, 0, 2, 163, 0, 0, 6, 3, 110, 115, 53, 192, 12, 192, 12, 0, 2, 0, 1, 0, 2, 163, 0, 0, 6, 3, 110, 115, 56, 192, 12, 192, 172, 0, 1, 0, 1, 0, 18, 117, 0, 0, 4, 68, 180, 131, 16, 192, 118, 0, 1, 0, 1, 0, 18, 117, 0, 0, 4, 68, 142, 255, 16, 192, 136, 0, 1, 0, 1, 0, 18, 117, 0, 0, 4, 203, 84, 221, 53, 192, 154, 0, 1, 0, 1, 0, 18, 117, 0, 0, 4, 98, 138, 11, 157, 192, 208, 0, 1, 0, 1, 0, 18, 117, 0, 0, 4, 119, 160, 247, 124, 192, 190, 0, 1, 0, 1, 0, 2, 163, 0, 0, 4, 202, 43, 223, 170, 192, 226, 0, 1, 0, 1, 0, 2, 163, 0, 0, 4, 202, 165, 104, 22 }; IByteReader reader = new ByteReader(response); new DNS.MessageingConcretes.Question(reader); //Just to advance the position var expectedRr = new ResourceRecord(null) { Class = RecordClass.In, Name = "yahoo.com.", Rdata = new byte[] { 0, 1, 4, 109, 116, 97, 55, 3, 97, 109, 48, 8, 121, 97, 104, 111, 111, 100, 110, 115, 3, 110, 101, 116, 0 }, RdLength = 25, Ttl = 1800, Type = RecordType.MxRecord, Record = new DNS.RDataConcretes.MxRecord(null) { Preference = 1, Exchanger = "mta7.am0.yahoodns.net.", }, }; var actualRr = new ResourceRecord(reader); AssertEquality(expectedRr, actualRr); var expectedMx = new MxRecord { Class = RecordClass.In, Name = "yahoo.com.", Ttl = 1800, Type = RecordType.MxRecord, Preference = 1, Exchanger = "mta7.am0.yahoodns.net." }; var actualMx = actualRr.ConvertToExternalType() as MxRecord; AssertEquality(expectedMx, actualMx); }
public void ToRecord(ResourceRecord record) { ObjectCopy.Copy(this, record); }
/// <summary> /// Initializes a new instance of the <see cref="EmptyRecord"/> class. /// </summary> /// <param name="info">The information.</param> /// <exception cref="System.ArgumentNullException">If <paramref name="info"/> is null.</exception> public EmptyRecord(ResourceRecord info) : base(info) { }
/// <summary> /// Initializes a new instance of the <see cref="MgRecord"/> class. /// </summary> /// <param name="info">The information.</param> /// <param name="domainName">The domain name.</param> /// <exception cref="System.ArgumentNullException">If <paramref name="domainName"/> or <paramref name="info"/> is null.</exception> public MgRecord(ResourceRecord info, DnsString domainName) : base(info) { MgName = domainName ?? throw new ArgumentNullException(nameof(domainName)); }
/// <summary> /// Initializes a new instance of the <see cref="CNameRecord"/> class. /// </summary> /// <param name="info">The information.</param> /// <param name="canonicalName">The canonical name.</param> /// <exception cref="System.ArgumentNullException">If <paramref name="canonicalName"/> or <paramref name="info"/> is null.</exception> public CNameRecord(ResourceRecord info, DnsString canonicalName) : base(info) { CanonicalName = canonicalName ?? throw new ArgumentNullException(nameof(canonicalName)); }
public HInfoRecord ReadResourceRecord( ResourceRecord info, DnsDatagramReader reader) => new HInfoRecord(info, reader.ReadString(), reader.ReadString());
public Task <Result> FindValue(string ip, string search) { var services = Utils.LoadMdnsServices(); var result = new Result { FoundAt = ServiceName }; try { foreach (var service in services) { try { Message msg = Lookup(service).GetAwaiter().GetResult(); if (msg != null) { var random = new Random(); #region Store result ResourceRecord record = msg.Answers.FirstOrDefault(); if (msg.AdditionalRecords != null) { ARecord = (AddressRecord)msg .AdditionalRecords.Find(x => x.Type.Equals(DnsType.A)); TRecord = (TXTRecord)msg .AdditionalRecords.Find(x => x.Type.Equals(DnsType.TXT)); var DeviceName = Utils.Common; var DeviceId = Utils.Common; if (ARecord?.Address.ToString().Equals(ip) == true) { DeviceId = ARecord.Name.Labels .FirstOrDefault()?.Replace("-", "") ?? Utils.Common; DeviceName = ARecord.Name.Labels .FirstOrDefault() ?? Utils.Common; } if (TRecord != null) { var prop = TRecord.Strings.Find(x => x.Contains("fn")); if (prop != null) { var info = prop.Split("="); DeviceName = info[0]; } } switch (search.ToUpper()) { case "SYSTEMNAME": result.Value = DeviceName; break; case "SERIAL": result.Value = DeviceId; break; } if (ARecord != null || TRecord != null) { // Uow.Commit(foundDevice); return(Task.Run(() => result)); } } else { // ToDo: what should I do then... } #endregion } } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(Task.Run(() => new Result() { Value = Utils.Common })); } catch (Exception) { return(Task.Run(() => new Result() { Value = Utils.Common })); } }
/// <summary> /// Initializes a new instance of the <see cref="AaaaRecord"/> class. /// </summary> /// <inheritdoc /> public AaaaRecord(ResourceRecord info, IPAddress address) : base(info, address) { }
public ResourceRecord FromBytes(byte[] bytes, int start, out int totalBytesRead) { var name = this.dnsSerializer.ParseQuestionName(bytes, start, out var bytesRead); totalBytesRead = bytesRead; var recordType = DeserializeRecordType(bytes, start + totalBytesRead); totalBytesRead += 2; // count the record class bytes. totalBytesRead += 2; var timeToLive = Read4BytesAsInt(bytes, start + totalBytesRead); totalBytesRead += 4; var length = DnsQuestionBinarySerializer.Read2BytesAsInt(bytes, start + totalBytesRead); totalBytesRead += 2; ResourceRecord result = null; switch (recordType) { case RecordType.A: result = new ARecord() { Name = name, TimeToLive = timeToLive, Address = new System.Net.IPAddress(new ReadOnlySpan <byte>(bytes, start + totalBytesRead, 4)), }; break; case RecordType.CNAME: result = new CNameRecord() { Name = name, TimeToLive = timeToLive, CName = this.dnsSerializer.ParseQuestionName(bytes, start + totalBytesRead, out var cnameBytesRead), }; break; case RecordType.NS: result = new NSRecord() { Name = name, TimeToLive = timeToLive, DName = this.dnsSerializer.ParseQuestionName(bytes, start + totalBytesRead, out var dnameBytesRead), }; break; case RecordType.MX: result = this.DeserializeMxRr(name, timeToLive, bytes, start + totalBytesRead, out var rdataSize); break; case RecordType.PTR: result = this.DeserializePtrRr(name, timeToLive, bytes, start + totalBytesRead, out var ptrSize); break; case RecordType.TXT: result = this.DeserializeTxtRr(name, timeToLive, bytes, start + totalBytesRead, length, out var txtSize); break; case RecordType.SOA: result = this.DeserializeSoaRr(name, timeToLive, bytes, start + totalBytesRead, out var soaSize); break; default: Console.WriteLine($"Deserialization of recordType {recordType} is not yet implemented."); result = null; break; } totalBytesRead += length; return(result); }
/// <summary> /// Parse a ResourceRecord represented as a byte array. /// </summary> /// <param name="data">The byte array.</param> /// <param name="offset">The offset to start parsing from.</param> /// <returns>A parsed ResourceRecord.</returns> public static ResourceRecord Parse(byte[] data, ref int offset) { ResourceRecord record = new ResourceRecord(); record.UncompressedName = QuestionName.ExtractName(data, ref offset); record.Type = (ResourceRecordType)((data[offset++] << 8) + data[offset++]); record.Class = (ResourceRecordClass)((data[offset++] << 8) + data[offset++]); record.TTL = (uint)((data[offset++] << 24) + (data[offset++] << 16) + (data[offset++] << 8) + data[offset++]); int length = (ushort)((data[offset++] << 8) + data[offset++]); if (length > 0) { record.Data = new byte[length]; for (int i = 0; i < length; i++) record.Data[i] = data[offset++]; } else record.Data = null; return record; }
/// <summary> /// Initializes a new instance of the <see cref="PtrRecord"/> class. /// </summary> /// <param name="info">The information.</param> /// <param name="ptrDomainName">The domain name.</param> /// <exception cref="System.ArgumentNullException">If <paramref name="info"/> or <paramref name="ptrDomainName"/> is null.</exception> public PtrRecord(ResourceRecord info, DnsString ptrDomainName) : base(info) { PtrDomainName = ptrDomainName ?? throw new ArgumentNullException(nameof(ptrDomainName)); }
/// <summary> /// Initializes a new instance of the <see cref="AfsDbRecord"/> class. /// </summary> /// <param name="info">The information.</param> /// <param name="type">The type.</param> /// <param name="name">The name.</param> /// <exception cref="System.ArgumentNullException">If <paramref name="info"/> or <paramref name="name"/> is null.</exception> public AfsDbRecord(ResourceRecord info, AfsType type, DnsString name) : base(info) { SubType = type; Hostname = name ?? throw new ArgumentNullException(nameof(name)); }
/// <summary> /// Initializes a new instance of the <see cref="MInfoRecord"/> class. /// </summary> /// <param name="info">The information.</param> /// <param name="rmailBox">The <c>RMAILBX</c>.</param> /// <param name="emailBox">The <c>EMAILBX</c>.</param> /// <exception cref="ArgumentNullException">If <paramref name="info"/> or <paramref name="rmailBox"/> or <paramref name="emailBox"/> is null.</exception> public MInfoRecord(ResourceRecord info, DnsString rmailBox, DnsString emailBox) : base(info) { RMailBox = rmailBox ?? throw new ArgumentNullException(nameof(rmailBox)); EmailBox = emailBox ?? throw new ArgumentNullException(nameof(emailBox)); }