tdns/Tesses.Dns/Entry.cs

46 lines
1.2 KiB
C#
Raw Normal View History

2022-07-24 20:09:33 +00:00
using System.Net;
using DNS.Protocol;
using DNS.Protocol.ResourceRecords;
public class DNSEntry
{
public DNSEntry()
{
Key="";
Value="";
Type="A";
}
public int Id {get;set;}
public string Key {get;set;}
public string Value {get;set;}
public string Type {get;set;}
public int TTL {get;set;}
public static IResourceRecord? GetDNSEntry(IEnumerable<DNSEntry> entry,Question q)
{
foreach(var item in entry)
{
if(q.Type == RecordType.A && item.Type=="A")
{
if(item.Key == q.Name.ToString())
{
IResourceRecord record = new IPAddressResourceRecord(
q.Name, IPAddress.Parse(item.Value),TimeSpan.FromSeconds(item.TTL));
return record;
}
}
if(q.Type == RecordType.CNAME && item.Type=="CNAME")
{
if(item.Key == q.Name.ToString())
{
IResourceRecord record = new CanonicalNameResourceRecord(
q.Name,new Domain(item.Value),TimeSpan.FromSeconds(item.TTL));
return record;
}
}
}
return null;
}
}