/// <summary>
 /// 初始化Nekoxy代理
 /// </summary>
 private void InitProxy()
 {
     HttpProxy.Shutdown();
     HttpProxy.Startup(DataUtil.Config.localProxyPort, false, false);
     HttpProxy.AfterSessionComplete += s => Task.Run(() => ProcessData(s));
     ApplyProxySettings();
 }
Exemple #2
0
        /// <summary>
        /// 通信の受信を開始します。
        /// </summary>
        /// <param name="portID">受信に使用するポート番号。</param>
        /// <param name="UIControl">GUI スレッドで実行するためのオブジェクト。中身は何でもいい</param>
        /// <returns>実際に使用されるポート番号。</returns>
        public int Start(int portID, Control UIControl)
        {
            StopFiddler();
            StartFiddler();

            Utility.Configuration.ConfigurationData.ConfigConnection c = Utility.Configuration.Config.Connection;


            this.UIControl = UIControl;


            HttpProxy.Shutdown();
            try
            {
                HttpProxy.UpstreamProxyConfig = new ProxyConfig(ProxyConfigType.SpecificProxy, "127.0.0.1", FiddlerProxyPort);

                HttpProxy.Startup(portID, false, false);
                ProxyPort = portID;


                ProxyStarted();

                Utility.Logger.Add(2, string.Format("APIObserver: ポート {0} 番で受信を開始しました。", portID));
            }
            catch (Exception ex)
            {
                Utility.Logger.Add(3, "APIObserver: 受信開始に失敗しました。" + ex.Message);
                ProxyPort = 0;
            }


            return(ProxyPort);
        }
        public void Startup(int proxy = 37564)
        {
            this.ListeningPort = proxy;

            HttpProxy.Startup(proxy, false, false);
            this.ApplyUpstreamProxySettings();

            this.compositeDisposable.Add(this.connectableSessionSource.Connect());
            this.compositeDisposable.Add(this.apiSource.Connect());
        }
Exemple #4
0
        public void Startup(int proxy = 0)
        {
            if (proxy < 1024)
            {
                proxy = new Random().Next(1024, 65535);
            }

            FiddlerApplication.BeforeRequest += this.Fiddler_BeforeRequest;
            HttpProxy.Startup(proxy);
            this.compositeDisposable.Add(this.connectableSessionSource.Connect());
            this.compositeDisposable.Add(this.apiSource.Connect());
        }
Exemple #5
0
        static void Main(string[] args)
        {
            //token = "63d60903eab97f3ddbb88ef213db3cf1";
            downloadServerInfo();
            HttpProxy.Shutdown();
            //HttpProxy.UpstreamProxyConfig = new ProxyConfig(ProxyConfigType.SpecificProxy, null, 8000);
            HttpProxy.AfterSessionComplete += sessionComplete;

            Console.WriteLine("代理开启:0.0.0.0:8888...");
            HttpProxy.Startup(8888, false, false);
            Console.ReadKey();
        }
Exemple #6
0
 private static void Main(string[] args)
 {
     HttpProxy.Shutdown();
     HttpProxy.UpstreamProxyConfig = new ProxyConfig(ProxyConfigType.SpecificProxy, "127.0.0.1", 8888);
     HttpProxy.Startup(12345, false, false);
     HttpProxy.AfterReadRequestHeaders  += r => Task.Run(() => Console.WriteLine(r));
     HttpProxy.AfterReadResponseHeaders += r => Task.Run(() => Console.WriteLine(r));
     HttpProxy.AfterSessionComplete     += s => Task.Run(() => Debug.WriteLine(s));
     //HttpProxy.AfterSessionComplete += s => Task.Run(() => Debug.WriteLine(s.Response.BodyAsString));
     while (true)
     {
         System.Threading.Thread.Sleep(1000);
     }
 }
Exemple #7
0
        public void Startup(int proxy = 37564)
        {
            //UpstreamProxySettings == null は SystemProxy使用とみなす
            var isSetIEProxySettings = this.UpstreamProxySettings == null || this.UpstreamProxySettings.Type != ProxyType.DirectAccess;

            HttpProxy.Startup(proxy, false, isSetIEProxySettings);

            //プロキシを使用しない場合、HTTPだけNekoxyを通し、後は直アクセス
            if (!isSetIEProxySettings)
            {
                WinInetUtil.SetProxyInProcess("http=localhost:" + proxy, "local");
            }

            this.compositeDisposable.Add(this.connectableSessionSource.Connect());
            this.compositeDisposable.Add(this.apiSource.Connect());
        }
Exemple #8
0
        public void startProxy(int port)
        {
            if (!im.serverHelper.downloadServerInfo())
            {
                im.uiHelper.setStatusBarText("服务器列表获取失败!");
                return;
            }

            int servernum = im.serverHelper.getServersNumber();

            HttpProxy.Shutdown();

            HttpProxy.AfterSessionComplete += (obj) => Task.Run(() => { processData(obj); });
            HttpProxy.Startup(port, false, false);

            string proxyaddr = String.Format("{0}:{1}", im.serverHelper.getLocalAddress(), port);

            im.uiHelper.setStatusBarText(String.Format("代理在{0}上开启成功,等待连接……已添加{1}个服务器", proxyaddr, servernum));
        }
Exemple #9
0
        /// <summary>
        /// 通信の受信を開始します。
        /// </summary>
        /// <param name="portID">受信に使用するポート番号。</param>
        /// <param name="UIControl">GUI スレッドで実行するためのオブジェクト。中身は何でもいい</param>
        /// <returns>実際に使用されるポート番号。</returns>
        public int Start(int portID, Control UIControl)
        {
            Utility.Configuration.ConfigurationData.ConfigConnection c = Utility.Configuration.Config.Connection;


            this.UIControl = UIControl;


            HttpProxy.Shutdown();
            try
            {
                if (c.UseUpstreamProxy)
                {
                    HttpProxy.UpstreamProxyConfig = new ProxyConfig(ProxyConfigType.SpecificProxy, c.UpstreamProxyAddress, c.UpstreamProxyPort);
                }
                else if (c.UseSystemProxy)
                {
                    HttpProxy.UpstreamProxyConfig = new ProxyConfig(ProxyConfigType.SystemProxy);
                }
                else
                {
                    HttpProxy.UpstreamProxyConfig = new ProxyConfig(ProxyConfigType.DirectAccess);
                }

                HttpProxy.Startup(portID, false, false);
                ProxyPort = portID;


                ProxyStarted();

                Utility.Logger.Add(2, string.Format("APIObserver: ポート {0} 番で受信を開始しました。", portID));
            }
            catch (Exception ex)
            {
                Utility.Logger.Add(3, "APIObserver: 受信開始に失敗しました。" + ex.Message);
                ProxyPort = 0;
            }


            return(ProxyPort);
        }
Exemple #10
0
        public bool startProxy(int port)
        {
            try
            {
                HttpProxy.Shutdown();

                HttpProxy.AfterSessionComplete += (obj) => Task.Run(() => { WaitForServerDownload(obj); });
                //HttpProxy.AfterSessionComplete += (obj) => Task.Run(() => { processData(obj); });
                HttpProxy.Startup(port, false, false);
            }
            catch (Exception)
            {
                im.uiHelper.setStatusBarText(String.Format("端口{0}已被占用!请尝试更换端口!", port));
                return(false);
            }

            string proxyaddr = String.Format("{0}:{1}", im.serverHelper.GetLocalAddress(), port);

            im.uiHelper.setStatusBarText(String.Format("代理在{0}上开启成功,等待连接……", proxyaddr));
            return(true);
        }
Exemple #11
0
        private Proxy()
        {
            this.Handlers = new List <ProxyHandler>();
            if (Helper.IsInDesignMode)
            {
                return;
            }

            HttpProxy.Startup(49217, false, true);
            HttpProxy.AfterSessionComplete += (_ =>
            {
                var handlers = this.Handlers.ToArray();
                foreach (var x in handlers)
                {
                    if ((x.Where == null) || (_.Request.PathAndQuery == x.Where))
                    {
                        x.Handler.Invoke(_);
                    }
                }
                ;
            });
        }