tdns/Tesses.Dns/Entry.cs

46 lines
1.2 KiB
C#

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