Exemple #1
0
 public ProxyListener(ProxyConfig config)
     : base(config.HttpAddress, config.HttpPort)
 {
     Port    = config.HttpPort;
     Version = config.Version;
     Config  = config;
 }
        /// <summary>
        /// Creates a new SocksWebProxy
        /// </summary>
        /// <param name="config">Proxy settings</param>
        /// <param name="allowBypass">Whether to allow bypassing the proxy server. 
        /// The current implementation to allow bypassing the proxy server requiers elevated privileges. 
        /// If you want to use the library in an environment with limited privileges (like Azure Websites or Azure Webjobs), set allowBypass = false</param>
        /// <returns></returns>
        public SocksWebProxy(ProxyConfig config = null, bool allowBypass = true)
        {
            if (config == null)
                config = ProxyConfig.Settings ?? new ProxyConfig();

            Config = config;
            GetListener(config, allowBypass);
        }
        private ProxyListener GetListener(ProxyConfig config, bool allowBypass = true)
        {   
            lock(locker)
            {
                SocksWebProxy.allowBypass = allowBypass;
                if (listeners == null)
                    listeners = new List<ProxyListener>();

                var listener = listeners.Where(x => x.Port == config.HttpPort).FirstOrDefault();

                if(listener == null)
                {
                    listener = new ProxyListener(config);
                    listener.Start();
                    listeners.Add(listener);
                }

                if (listener.Version != config.Version) 
                    throw new Exception("Socks Version Mismatch for Port " + config.HttpPort);

                return listener;
            }
        }
 public ProxyClient(ProxyConfig config, Socket ClientSocket, DestroyDelegate Destroyer)
     : base(ClientSocket, Destroyer)
 {
     Config = config;
 }
Exemple #5
0
        public static WebClient GetTorWebClient()
        {
            WebClient wc = new WebClient();
            if (NetworkAdapter.OpenVpnAdapter!=null && NetworkAdapter.OpenVpnAdapter.IsConnected)
            {
                return wc;
            }
            try
            {
                var proxyConfig = new ProxyConfig(
                    //This is an internal http->socks proxy that runs in process
                 IPAddress.Parse(Settings.BrowserProxy),
                    //This is the port your in process http->socks proxy will run on
                 53549,
                    //This could be an address to a local socks proxy (ex: Tor / Tor Browser, If Tor is running it will be on 127.0.0.1)
                 IPAddress.Parse(Settings.BrowserProxy),
                    //This is the port that the socks proxy lives on (ex: Tor / Tor Browser, Tor is 9150)
                 9150,
                    //This Can be Socks4 or Socks5
                 ProxyConfig.SocksVersion.Five
                 );
                var proxy = new SocksWebProxy(proxyConfig);

                wc.Proxy = proxy;// new WebProxy(Settings.BrowserProxy, true);
            }
            catch (Exception ex)
            {
                Logging.Log("Error: not able to establish Tor proxy.");
            }

            return wc;
        }
 /// <summary>
 /// Creates a new SocksWebProxy
 /// </summary>
 /// <param name="config">Proxy settings</param>
 /// <param name="allowBypass">Whether to allow bypassing the proxy server. 
 /// The current implementation to allow bypassing the proxy server requiers elevated privileges. 
 /// If you want to use the library in an environment with limited privileges (like Azure Websites or Azure Webjobs), set allowBypass = false</param>
 /// <returns></returns>
 public SocksWebProxy(ProxyConfig config = null, bool allowBypass = true)
 {
     Config = config;
     GetListener(config, allowBypass);
 }