public void Start() { GetProcessors(); server_ = new DnsServer(IPAddress.Any, state_.Config.Dns.UdpListeners, state_.Config.Dns.TcpListeners, ProcessDnsQuery); server_.Start(); }
public DnsServer(IDictionary <string, DomainMapping> mappingLookup) { this.mappingLookup = mappingLookup; server = new ARSoft.Tools.Net.Dns.DnsServer(IPAddress.Any, 10, 10, ProcessQuery); server.ExceptionThrown += (o, e) => { Console.WriteLine("DnsServer threw an exception " + o + " " + e); }; }
public DnsServer(IDictionary<string, DomainMapping> mappingLookup) { this.mappingLookup = mappingLookup; server = new ARSoft.Tools.Net.Dns.DnsServer(IPAddress.Any, 10, 10, ProcessQuery); server.ExceptionThrown += (o, e) => { Console.WriteLine("DnsServer threw an exception " + o + " " + e); }; }
static void Main(string[] args) { using (DnsServer server = new DnsServer(IPAddress.Any, 10, 10, ProcessQuery)) { server.Start(); Console.WriteLine("Press any key to stop server"); Console.ReadLine(); } }
public DnsServer(Database.Database db, int udpPort = 53, int tcpPort = 53, List <IPAddress> fallbackIpAddress = null) { this.db = db; if (fallbackIpAddress != null) { dnsFallback = new DnsClient(fallbackIpAddress, 2000); } dnsServer = new ARSoft.Tools.Net.Dns.DnsServer(udpPort, tcpPort); dnsServer.QueryReceived += Server_QueryReceived; }
public static void Main(string[] args) { new Core.DataAccess.SQL.ModelMappings().Create(); var kernel = NinjectCommon.CreateKernel(); var dnsQueryHandler = kernel.Get<IDnsQueryHandler>(); using (var server = new DnsServer(IPAddress.Any, 10, 10, dnsQueryHandler.HandleQuery )) { server.Start(); Console.WriteLine("Press enter to stop server"); Console.ReadLine(); } }
public void StartServer(int?listnerPort = null) { var ipEndPoint = new IPEndPoint(IPAddress.Any, listnerPort ?? DefaultDnsPort); _server = new ARSoft.Tools.Net.Dns.DnsServer(ipEndPoint, 10000, 10000); _server.ClientConnected += OnClientConnected; _server.QueryReceived += OnQueryReceived; _server.Start(); _logger.LogInformation("Server is started"); }
protected void StartDnsServer() { try { DnsServer server = new DnsServer(System.Net.IPAddress.Any, 10, 10, OnDnsQuery); this.AddListItem("Started DNS proxy..."); server.ExceptionThrown += DnsServer_ExceptionThrown; server.Start(); } catch (Exception e) { this.AddListItem(String.Format("ERROR STARTING DNS SERVER: {0}", e.Message)); } }
static void Main(string[] args) { using (DnsServer server = new DnsServer(IPAddress.Any, 4, 1)) { server.ClientConnected += OnClientConnected; server.QueryReceived += OnQueryReceived; server.Start(); Application.Run(); //Console.WriteLine("Press any key to stop server"); //Console.ReadLine(); } }
public static void Main(string[] args) { Console.WriteLine("-------------------------------------------------"); Console.WriteLine("DnsServerTest"); Console.WriteLine("-------------------------------------------------"); domain = System.Configuration.ConfigurationManager.AppSettings["Domain"]; if (domain == null) { Console.WriteLine(string.Format("AppSetting \"Domain\" invalid", domain)); Console.WriteLine("End"); Console.ReadKey(); return; } int.TryParse(System.Configuration.ConfigurationManager.AppSettings["TtlSeconds"], out ttlSeconds); if (ttlSeconds <= 0) { Console.WriteLine(string.Format("AppSetting \"TtlSeconds\" invalid", domain)); Console.WriteLine("End"); Console.ReadKey(); return; } Console.WriteLine(string.Format("Domain: {0}", domain)); Console.WriteLine(string.Format("TTL: {0} seconds", ttlSeconds.ToString("#,##0"))); Console.WriteLine(); using (DnsServer server = new DnsServer(10, 10)) { server.QueryReceived += OnQueryReceived; server.Start(); Console.WriteLine("Service started"); Console.WriteLine(); Console.WriteLine("\r\nPress any key to stop server"); Console.ReadLine(); return; } }
private ReturnCode ValidateTSig(byte[] resultData, DnsServer.SelectTsigKey tsigKeySelector, byte[] originalMac) { byte[] keyData; if ((TSigOptions.Algorithm == TSigAlgorithm.Unknown) || (tsigKeySelector == null) || ((keyData = tsigKeySelector(TSigOptions.Algorithm, TSigOptions.Name)) == null)) { return ReturnCode.BadKey; } else if (((TSigOptions.TimeSigned - TSigOptions.Fudge) > DateTime.Now) || ((TSigOptions.TimeSigned + TSigOptions.Fudge) < DateTime.Now)) { return ReturnCode.BadTime; } else if ((TSigOptions.OriginalMac == null) || (TSigOptions.OriginalMac.Length == 0)) { return ReturnCode.BadSig; } else { TSigOptions.KeyData = keyData; // maxLength for the buffer to validate: Original (unsigned) dns message and encoded TSigOptions // because of compression of keyname, the size of the signed message can not be used int maxLength = TSigOptions.StartPosition + TSigOptions.MaximumLength; if (originalMac != null) { // add length of mac on responses. MacSize not neccessary, this field is allready included in the size of the tsig options maxLength += originalMac.Length; } byte[] validationBuffer = new byte[maxLength]; int currentPosition = 0; // original mac if neccessary if ((originalMac != null) && (originalMac.Length > 0)) { EncodeUShort(validationBuffer, ref currentPosition, (ushort) originalMac.Length); EncodeByteArray(validationBuffer, ref currentPosition, originalMac); } // original unsiged buffer Buffer.BlockCopy(resultData, 0, validationBuffer, currentPosition, TSigOptions.StartPosition); // update original transaction id and ar count in message EncodeUShort(validationBuffer, currentPosition, TSigOptions.OriginalID); EncodeUShort(validationBuffer, currentPosition + 10, (ushort) _additionalRecords.Count); currentPosition += TSigOptions.StartPosition; // TSig Variables EncodeDomainName(validationBuffer, 0, ref currentPosition, TSigOptions.Name, false, null); EncodeUShort(validationBuffer, ref currentPosition, (ushort) TSigOptions.RecordClass); EncodeInt(validationBuffer, ref currentPosition, (ushort) TSigOptions.TimeToLive); EncodeDomainName(validationBuffer, 0, ref currentPosition, TSigAlgorithmHelper.GetDomainName(TSigOptions.Algorithm), false, null); TSigRecord.EncodeDateTime(validationBuffer, ref currentPosition, TSigOptions.TimeSigned); EncodeUShort(validationBuffer, ref currentPosition, (ushort) TSigOptions.Fudge.TotalSeconds); EncodeUShort(validationBuffer, ref currentPosition, (ushort) TSigOptions.Error); EncodeUShort(validationBuffer, ref currentPosition, (ushort) TSigOptions.OtherData.Length); EncodeByteArray(validationBuffer, ref currentPosition, TSigOptions.OtherData); // Validate MAC KeyedHashAlgorithm hashAlgorithm = TSigAlgorithmHelper.GetHashAlgorithm(TSigOptions.Algorithm); hashAlgorithm.Key = keyData; return (hashAlgorithm.ComputeHash(validationBuffer, 0, currentPosition).SequenceEqual(TSigOptions.OriginalMac)) ? ReturnCode.NoError : ReturnCode.BadSig; } }
internal void Parse(byte[] resultData, bool isRequest, DnsServer.SelectTsigKey tsigKeySelector, byte[] originalMac) { int currentPosition = 0; TransactionID = ParseUShort(resultData, ref currentPosition); _flags = ParseUShort(resultData, ref currentPosition); int questionCount = ParseUShort(resultData, ref currentPosition); int answerRecordCount = ParseUShort(resultData, ref currentPosition); int authorityRecordCount = ParseUShort(resultData, ref currentPosition); int additionalRecordCount = ParseUShort(resultData, ref currentPosition); ParseQuestions(resultData, ref currentPosition, questionCount); ParseSection(resultData, ref currentPosition, _answerRecords, answerRecordCount); ParseSection(resultData, ref currentPosition, _authorityRecords, authorityRecordCount); ParseSection(resultData, ref currentPosition, _additionalRecords, additionalRecordCount); if (_additionalRecords.Count > 0) { int tSigPos = _additionalRecords.FindIndex(record => (record.RecordType == RecordType.TSig)); if (tSigPos == (_additionalRecords.Count - 1)) { TSigOptions = (TSigRecord) _additionalRecords[tSigPos]; _additionalRecords.RemoveAt(tSigPos); TSigOptions.ValidationResult = ValidateTSig(resultData, tsigKeySelector, originalMac); } } FinishParsing(); }
public static DnsMessageBase Create(byte[] resultData, bool isRequest, DnsServer.SelectTsigKey tsigKeySelector, byte[] originalMac) { int flagPosition = 2; ushort flags = ParseUShort(resultData, ref flagPosition); DnsMessageBase res; switch ((OperationCode) ((flags & 0x7800) >> 11)) { case OperationCode.Update: res = new DnsUpdateMessage(); break; default: res = new DnsMessage(); break; } res.Parse(resultData, isRequest, tsigKeySelector, originalMac); return res; }
public DnsListener(StatefulServiceContext context) { _server = new ARSoft.Tools.Net.Dns.DnsServer(10, 10); _server.QueryReceived += _server_QueryReceived; client = new DnsClient(System.Net.IPAddress.Parse("114.114.114.114"), 5); }
/// <summary> /// Attempt to start the server. /// </summary> /// <remarks>Will only start when 'start-enabled' is true.</remarks> /// <returns>True on success, false if the server is not enabled.</returns> public bool Start() { if (_dnsServer != null) { throw new Exception("The server is already running."); } if (!Configuration.ServerEnabled) { // Server not enabled return false; } _dnsServer = new DnsServer(Configuration.ServerBindIP, 32, 32, OnQuery); Logger.Log(LogSeverity.Info, "Starting the TorDNS server. Bind IP: {0}", Configuration.ServerBindIP.ToString()); RefreshConfiguration(true); _dnsServer.Start(); IsRunning = true; return true; }
private static void BindListener(string ipAddressForBinding) { IPAddress ip; if (!IPAddress.TryParse(ipAddressForBinding, out ip)) return; if (Servers.ContainsKey(ipAddressForBinding)) return; var dnsServer = new DnsServer(ip, 10, 10); dnsServer.QueryReceived += OnQueryReceived; Servers.Add(ipAddressForBinding, dnsServer); dnsServer.Start(); var appLog = new System.Diagnostics.EventLog {Source = "Hyper-V Dns Proxy"}; appLog.WriteEntry($"Started DNS Service on {ipAddressForBinding}"); }
private static void StartServer() { Console.Write("Starting Nameserver.... "); if (server == null) { server = new DnsServer(IPAddress.Any, 10, 10, ProcessQuery); server.ExceptionThrown += server_ExceptionThrown; Ok = false; } try { server.Start(); Console.WriteLine("Done."); Ok = true; } catch (SocketException ex) { ConsoleUtils.WriteWarning("Unable to start nameserver, port 53 may be in use. " + ex.Message); Ok = false; } }
public void Stop() { if (!IsRunning) { return; } try { Logger.Log(LogSeverity.Info, "Stopping the TorDNS server."); _dnsServer.Stop(); } finally { _dnsServer = null; IsRunning = false; } }
internal VelvetService(IDnsLookup dnsLookup) { this.dnsLookup = dnsLookup; this.dnsServer = new DnsServer(IPAddress.Any, 10, 10, dnsLookup.ProcessQuery); }