コード例 #1
0
        public void Start()
        {
            GetProcessors();

            server_ = new DnsServer(IPAddress.Any, state_.Config.Dns.UdpListeners, state_.Config.Dns.TcpListeners, ProcessDnsQuery);
            server_.Start();
        }
コード例 #2
0
        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);
            };
        }
コード例 #3
0
        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);
                };
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: jorik041/NeuroDNS
        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();
            }
        }
コード例 #5
0
        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;
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: nathantreid/kolo-ns
        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();
            }
        }
コード例 #7
0
ファイル: DnsServer.cs プロジェクト: BLun78/DnsProxy
        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");
        }
コード例 #8
0
ファイル: frmMain.cs プロジェクト: Belala/MissVenom
 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));
     }
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: meetshawn/DNSProxy
        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();
            }

            
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: educoutinho/DnsServerTest
        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;
            }
        }
コード例 #11
0
		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;
			}
		}
コード例 #12
0
		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();
		}
コード例 #13
0
		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;
		}
コード例 #14
0
ファイル: DnsListener.cs プロジェクト: wingfeng/dnsonsf
 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);
 }
コード例 #15
0
ファイル: TorDNS.cs プロジェクト: LETO-R/TorDNSd
        /// <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;
        }
コード例 #16
0
        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}");
        }
コード例 #17
0
        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;
            }
        }
コード例 #18
0
ファイル: TorDNS.cs プロジェクト: LETO-R/TorDNSd
        public void Stop()
        {
            if (!IsRunning)
            {
                return;
            }

            try
            {
                Logger.Log(LogSeverity.Info, "Stopping the TorDNS server.");
                _dnsServer.Stop();
            }
            finally
            {
                _dnsServer = null;
                IsRunning = false;
            }
        }
コード例 #19
0
ファイル: VelvetService.cs プロジェクト: trullock/Velvet
 internal VelvetService(IDnsLookup dnsLookup)
 {
     this.dnsLookup = dnsLookup;
     this.dnsServer = new DnsServer(IPAddress.Any, 10, 10, dnsLookup.ProcessQuery);
 }