Esempio n. 1
0
        private void ProcessQuery(string query)
        {
            IPAddress address = DnsCache.GetIPAddress(this.host);

            if (address == null)
            {
                this.SendDnsLookupFailedPage(this.host);
                return;
            }
            IPEndPoint remoteEndPoint = new IPEndPoint(address, this.port);

            RemoteSocket = new Socket(remoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            if (this.headerFields.ContainsKey("Proxy-Connection") &&
                string.Equals(this.headerFields["Proxy-Connection"], "keep-alive", StringComparison.OrdinalIgnoreCase))
            {
                RemoteSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
            }
            try
            {
                RemoteSocket.BeginConnect(remoteEndPoint, this.OnConnected, RemoteSocket);
            }
            catch (Exception ex)
            {
                Dispose();
                Helper.PublishException(ex);
            }
        }
Esempio n. 2
0
 static void Debug()
 {
     while (true)
     {
         var input = Console.ReadKey();
         Console.WriteLine();
         if (input.Key == ConsoleKey.E)
         {
             Proxy.Stop();
             return;
         }
         else if (input.Key == ConsoleKey.H)
         {
             Console.WriteLine("H:Help; E:Exit; D:Dns; C:Clients; S:SaveConfig; I:ImportConfig");
         }
         else if (input.Key == ConsoleKey.D)
         {
             Console.WriteLine(DnsCache.ToDebugString());
         }
         else if (input.Key == ConsoleKey.C)
         {
             Console.WriteLine(Proxy.Listeners[0].GetClientsDebugString());
         }
         else if (input.Key == ConsoleKey.S)
         {
             ConfigManager.SaveConfiguration();
             Console.WriteLine("config.xml saved");
         }
         else if (input.Key == ConsoleKey.I)
         {
             ConfigManager.LoadConfiguration();
             Console.WriteLine("config.xml imported");
         }
         else if (input.Key == ConsoleKey.Delete)
         {
             DnsCache.Clear();
             Console.WriteLine("Cache cleared");
         }
         else if (input.Key == ConsoleKey.Home)
         {
             Proxy.Start();
         }
         else if (input.Key == ConsoleKey.End)
         {
             Proxy.Stop();
         }
     }
 }
Esempio n. 3
0
        public Listener(ListenerType type, string host, int port)
        {
            IPAddress address;

            if (!IPAddress.TryParse(host, out address))
            {
                address = DnsCache.GetIPAddress(host);
            }
            if (address == null)
            {
                throw new ArgumentException("host " + host + " not found.", "host");
            }
            if (port < 1 || port > 65535)
            {
                throw new ArgumentOutOfRangeException("port[" + port + "] out of range.", "port");
            }

            this._listenerType = type;
            this._address      = address;
            this._host         = host;
            this._port         = port;
            this._clients      = new SynchronizedCollection <IClient>();
        }