private void startServer(string serverAddress, List <string> officalServerAddress) { masterFile = new MasterFile(); server = new DnsServer(masterFile, "223.5.5.5"); if (radioButton1.Checked) { masterFile.AddIPAddressResourceRecord(officalServerAddress[0], serverAddress); } else if (radioButton2.Checked) { masterFile.AddIPAddressResourceRecord(officalServerAddress[1], serverAddress); } else if (radioButton3.Checked) { masterFile.AddIPAddressResourceRecord(officalServerAddress[2], serverAddress); } else if (radioButton4.Checked) { masterFile.AddIPAddressResourceRecord(officalServerAddress[3], serverAddress); } else if (radioButton5.Checked) { masterFile.AddIPAddressResourceRecord(officalServerAddress[4], serverAddress); } server.Listen(); }
static async Task startServer(string ip) { Console.WriteLine("Starting Nameserver to redirect all known Minecraft \"Featured Servers\" to " + ip); MasterFile masterFile = new MasterFile(); DnsServer server = new DnsServer(masterFile, "8.8.8.8"); // Resolve these domain to given ip masterFile.AddIPAddressResourceRecord("play.inpvp.net", ip); masterFile.AddIPAddressResourceRecord("mco.lbsg.net", ip); masterFile.AddIPAddressResourceRecord("mco.mineplex.com", ip); masterFile.AddIPAddressResourceRecord("mco.cubecraft.net", ip); masterFile.AddIPAddressResourceRecord("hivebedrock.network", ip); // Log every request server.Requested += (sender, e) => Console.WriteLine(e.Request); // On every successful request log the request and the response server.Responded += (sender, e) => Console.WriteLine("{0} => {1}", e.Request, e.Response); // Log errors server.Errored += (sender, e) => Console.WriteLine(e.Exception.Message); // Start the server (by default it listents on port 53) Console.WriteLine("Looks like we are all set. Set your Switch's DNS to the IP of this computer!"); await server.Listen(); }
public async static Task MainAsync(string[] args) { MasterFile masterFile = new MasterFile(); DnsServer server = new DnsServer(masterFile, "8.8.8.8"); masterFile.remo foreach (string domain in args) { Console.WriteLine("Redirecting {0} to localhost", domain); masterFile.AddIPAddressResourceRecord(domain, "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(); }
static Socket DNS() { MasterFile masterFile = new MasterFile(); masterFile.AddIPAddressResourceRecord("*.iwara.tv", "141.101.120.83"); masterFile.AddIPAddressResourceRecord("t66y.com", "141.101.120.83"); masterFile.AddIPAddressResourceRecord("ajax.googleapis.com", "127.0.0.5"); Socket socket = LocalRequestResolver.CreateDNSServer(masterFile, IPAddress.Parse("114.114.114.114"), new IPEndPoint(IPAddress.Loopback, 54663), new IPEndPoint(IPAddress.Loopback, 36645)); return(socket); }
private async static Task RunDnsAsync(string backupDnsServer, params RedirectPair[] args) { MasterFile masterFile = new MasterFile(); DnsServer server = new DnsServer(masterFile, backupDnsServer); foreach (RedirectPair redirect in args) { masterFile.AddIPAddressResourceRecord(redirect.Domain, redirect.IPAddress); } await server.Run(); }
static void F() { // Proxy to google's DNS MasterFile masterFile = new MasterFile(); DnsServer server = new DnsServer(masterFile, "8.8.8.8"); // Resolve these domain to localhost masterFile.AddIPAddressResourceRecord("google.com", "127.0.0.1"); masterFile.AddIPAddressResourceRecord("github.com", "127.0.0.1"); // Log every request server.Requested += (sender, e) => Console.WriteLine(e.Request); // On every successful request log the request and the response server.Responded += (sender, e) => Console.WriteLine("{0} => {1}", e.Request, e.Response); // Log errors server.Errored += (sender, e) => Console.WriteLine(e.Exception.Message); // Start the server (by default it listens on port 53) server.Listen(); }
MasterFile GetMasterFile() { var basePath = AppDomain.CurrentDomain.BaseDirectory; var hostsPath = Path.Combine(basePath, "hosts.txt"); if (File.Exists(hostsPath) == false) { return(new MasterFile()); } string s = File.ReadAllText(hostsPath); var mf = new MasterFile(); foreach (var item in ParseHosts.CreateMasterFile(s)) { mf.AddIPAddressResourceRecord(item.Key, item.Value.ToString()); } return(mf); }
public async static Task MainAsync() { MasterFile masterFile = new MasterFile(); DnsServer server = new DnsServer(masterFile, "8.8.8.8"); masterFile.AddIPAddressResourceRecord("google.com", "127.0.0.1"); server.Requested += (request) => Console.WriteLine("Requested: {0}", request); server.Responded += (request, response) => Console.WriteLine("Responded: {0} => {1}", request, response); server.Errored += (e) => Console.WriteLine("Errored: {0}", e.Message); server.Listening += () => Console.WriteLine("Listening"); server.Listening += async() => { DnsClient client = new DnsClient("127.0.0.1", PORT); await client.Lookup("google.com"); await client.Lookup("cnn.com"); server.Dispose(); }; await server.Listen(PORT); }
public async Task TestResolve() { MasterFile masterFile = new MasterFile(); masterFile.AddIPAddressResourceRecord("google.com", "192.168.0.1"); { //Test matching case. IRequest clientRequest = new Request(); Question clientRequestQuestion = new Question(new Domain("google.com"), RecordType.A); clientRequest.Id = 1; clientRequest.Questions.Add(clientRequestQuestion); clientRequest.OperationCode = OperationCode.Query; IResponse clientResponse = await masterFile.Resolve(clientRequest); Assert.Equal(1, clientResponse.Id); Assert.Equal(1, clientResponse.Questions.Count); Assert.Equal(1, clientResponse.AnswerRecords.Count); Assert.Equal(0, clientResponse.AuthorityRecords.Count); Assert.Equal(0, clientResponse.AdditionalRecords.Count); Question clientResponseQuestion = clientResponse.Questions[0]; Assert.Equal(RecordType.A, clientResponseQuestion.Type); Assert.Equal("google.com", clientResponseQuestion.Name.ToString()); var clientResponseAnswer = clientResponse.AnswerRecords[0]; Assert.Equal(RecordType.A, clientResponseAnswer.Type); Assert.Equal("google.com", clientResponseAnswer.Name.ToString()); Assert.Equal("192.168.0.1", ((IPAddressResourceRecord)clientResponseAnswer).IPAddress.ToString()); } { //Test different casing. IRequest clientRequest = new Request(); Question clientRequestQuestion = new Question(new Domain("gooGLE.com"), RecordType.A); clientRequest.Id = 1; clientRequest.Questions.Add(clientRequestQuestion); clientRequest.OperationCode = OperationCode.Query; IResponse clientResponse = await masterFile.Resolve(clientRequest); Assert.Equal(1, clientResponse.Id); Assert.Equal(1, clientResponse.Questions.Count); Assert.Equal(1, clientResponse.AnswerRecords.Count); Assert.Equal(0, clientResponse.AuthorityRecords.Count); Assert.Equal(0, clientResponse.AdditionalRecords.Count); Question clientResponseQuestion = clientResponse.Questions[0]; Assert.Equal(RecordType.A, clientResponseQuestion.Type); Assert.Equal("gooGLE.com", clientResponseQuestion.Name.ToString()); var clientResponseAnswer = clientResponse.AnswerRecords[0]; Assert.Equal(RecordType.A, clientResponseAnswer.Type); Assert.Equal("google.com", clientResponseAnswer.Name.ToString()); Assert.Equal("192.168.0.1", ((IPAddressResourceRecord)clientResponseAnswer).IPAddress.ToString()); } { //Test RecordType.ANY IRequest clientRequest = new Request(); Question clientRequestQuestion = new Question(new Domain("google.com"), RecordType.ANY); clientRequest.Id = 1; clientRequest.Questions.Add(clientRequestQuestion); clientRequest.OperationCode = OperationCode.Query; IResponse clientResponse = await masterFile.Resolve(clientRequest); Assert.Equal(1, clientResponse.Id); Assert.Equal(1, clientResponse.Questions.Count); Assert.Equal(1, clientResponse.AnswerRecords.Count); Assert.Equal(0, clientResponse.AuthorityRecords.Count); Assert.Equal(0, clientResponse.AdditionalRecords.Count); Question clientResponseQuestion = clientResponse.Questions[0]; Assert.Equal(RecordType.ANY, clientResponseQuestion.Type); Assert.Equal("google.com", clientResponseQuestion.Name.ToString()); var clientResponseAnswer = clientResponse.AnswerRecords[0]; Assert.Equal(RecordType.A, clientResponseAnswer.Type); Assert.Equal("google.com", clientResponseAnswer.Name.ToString()); Assert.Equal("192.168.0.1", ((IPAddressResourceRecord)clientResponseAnswer).IPAddress.ToString()); } }
public static void SetDnsRedirects(MasterFile mF) { mF.AddIPAddressResourceRecord("manuals.playstation.net", GetLocalIPAddress()); mF.AddIPAddressResourceRecord("fjp01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("fus01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("fau01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("fuk01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("feu01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("fkr01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("fsa01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("ftw01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("fru01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("fmx01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("fcn01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("djp01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("dus01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("dau01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("duk01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("deu01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("dkr01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("dsa01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("dtw01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("dru01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("dmx01.ps5.update.playstation.net", "127.0.0.1"); mF.AddIPAddressResourceRecord("dcn01.ps5.update.playstation.net", "127.0.0.1"); }