Skip to content

Instantly share code, notes, and snippets.

@leachdaniel
Created January 14, 2018 15:15
Show Gist options
  • Save leachdaniel/d04c0ade5df059092656d9c4db13305c to your computer and use it in GitHub Desktop.
Save leachdaniel/d04c0ade5df059092656d9c4db13305c to your computer and use it in GitHub Desktop.
.Net DNS Server Example
//<PackageReference Include="DNS" Version="2.1.0" />
namespace DNSServer
{
class Program
{
static void Main(string[] args)
{
DNS.Server.DnsServer server = new DNS.Server.DnsServer("8.8.8.8");
server.Requested += Server_Requested;
server.Responded += Server_Responded;
server.Listen();
Console.WriteLine("DNS Server Started!");
Console.WriteLine("Press any key to quit!");
Console.ReadKey();
}
private static void Server_Responded(DNS.Protocol.IRequest request, DNS.Protocol.IResponse response)
{
foreach (var a in response.AnswerRecords)
{
Console.WriteLine($"Responded: {a.Name}:{System.Text.Encoding.UTF8.GetString(a.Data)}");
}
}
private static void Server_Requested(DNS.Protocol.IRequest request)
{
foreach (var q in request.Questions)
{
Console.WriteLine($"Requested: {q.Name}");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment