Skip to content

Instantly share code, notes, and snippets.

@erinxocon
Last active April 24, 2019 05:01
Show Gist options
  • Save erinxocon/1eeee2d09d803d6d9c7fc82910132b3d to your computer and use it in GitHub Desktop.
Save erinxocon/1eeee2d09d803d6d9c7fc82910132b3d to your computer and use it in GitHub Desktop.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RootNamespace>dns_interceptor</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DNS" Version="5.0.0" />
</ItemGroup>
</Project>
using System;
using System.Threading.Tasks;
using DNS.Server;
using DNS.Client;
namespace Examples.Server
{
class ServerExample
{
public static void Main(string[] args)
{
MainAsync(args).Wait();
}
public async static Task MainAsync(string[] args)
{
MasterFile masterFile = new MasterFile();
DnsServer server = new DnsServer(masterFile, "8.8.8.8");
// foreach (string domain in args)
// {
// Console.WriteLine("Redirecting {0} to localhost", domain);
// masterFile.AddIPAddressResourceRecord(domain, "127.0.0.1");
// }
Console.WriteLine("Redirecting {0} to localhost", "**");
masterFile.AddIPAddressResourceRecord("*.*", "127.0.0.1");
server.Responded += (sender, e) => Console.WriteLine("{0} => {1}", e.Request, e.Response);
server.Listening += (sender, e) => Console.WriteLine("Listening");
server.Errored += (sender, e) =>
{
Console.WriteLine("Errored: {0}", e.Exception);
ResponseException responseError = e.Exception as ResponseException;
if (responseError != null) Console.WriteLine(responseError.Response);
};
await server.Listen();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment