コード例 #1
0
ファイル: Proxy.cs プロジェクト: zgcwkj/TestBaiduPassword
        /// <summary>
        /// 抓取IP
        /// </summary>
        /// <param name="url">地址</param>
        private void CrawlIP(string url)
        {
            Thread.Sleep(50);
            //Goto 重新获取代理IP
RetryUrl:
            string str = HttpHelp.HttpGet(url);

            if (str == "" || str.Contains("-10"))
            {
                httpProxy.SwitchOff();
                goto RetryUrl;
            }
            string tbody = Regex.Match(str.Replace(" ", "").Replace("\r", "").Replace("\n", ""), @"<tbody>.+</tbody>").ToString();

            //Goto 重新获取代理IP
RetryIP:
            string proxya = Regex.Match(tbody, "<tddata-title=\"IP\">.+?</td>").ToString();
            string proxyb = Regex.Match(tbody, "<tddata-title=\"PORT\">.+?</td>").ToString();

            if (proxya == "" || proxyb == "")
            {
                return;
            }
            string _proxya = proxya.Replace("<tddata-title=\"IP\">", "").Replace("</td>", "");
            string _proxyb = proxyb.Replace("<tddata-title=\"PORT\">", "").Replace("</td>", "");

            File.AppendAllText(StaticClass.proxy, _proxya + ":" + _proxyb + "\r\n");
            tbody = tbody.Replace(proxya, "").Replace(proxyb, "");
            goto RetryIP;
        }
コード例 #2
0
        /// <summary>
        /// 启动IP代理服务
        /// </summary>
        /// <returns></returns>
        public bool startUp()
        {
            //记录Goto的次数
            int i = 0;
            //Goto 重新获取IP启动代理服务
            Retry:
            //Goto的次数自增
            i++;
            //尝试的次数达到一定的次数时退出
            if (i > 10) return false;
            //关闭代理服务
            if (GetSwitchState()) SwitchOff();

            #region 验证文件

            //文件不存在
            if (!File.Exists(StaticClass.proxy)) return false;
            //文件为空
            if (File.ReadAllText(StaticClass.proxy) == "") return false;
            //文件为空
            if (File.ReadAllText(StaticClass.proxy) == "\r\n") return false;

            #endregion 验证文件

            //获取电脑之前记录的代理IP
            string ip = GetProxyIp();
            //通过API获取代理数据
            try
            {
                string proxy = File.ReadAllText(StaticClass.proxy);
                string[] proxys = proxy.Replace("\r", "").Split('\n');
                ip = proxys[0];

                File.Delete(StaticClass.proxy);
                File.AppendAllText(StaticClass.proxy, proxy.Replace(ip + "\r\n", ""));
            }
            catch (Exception e)
            {
                string str = e.Message;
            }
            //设置代理IP
            SwitchOn(ip);
            //验证代理IP能否使用
            try
            {
                HttpHelp.HttpGet("https://blog.zgcwkj.top");
                return true;
            }
            catch (Exception e)
            {
                string str = e.Message;
                SwitchOff();
                //Goto 重试
                goto Retry;
            }
        }
コード例 #3
0
        /// <summary>
        /// 启动IP代理服务
        /// </summary>
        /// <param name="bout">次/回</param>
        /// <returns></returns>
        public bool startUp(int bout)
        {
            StaticClass.proxys = File.ReadAllText(StaticClass.proxy).Replace("\r", "").Split('\n');

            //关闭代理服务
            if (GetSwitchState())
            {
                SwitchOff();
            }

            //获取电脑之前记录的代理IP
            string ip = GetProxyIp();

            //通过API获取代理数据
            try
            {
                ip = StaticClass.proxys[bout];
            }
            catch (Exception e)
            {
                string str = e.Message;
            }
            //设置代理IP
            SwitchOn(ip);

            //验证代理IP能否使用
            try
            {
                HttpHelp.HttpGet("https://blog.zgcwkj.top");
                return(true);
            }
            catch (Exception e)
            {
                string str = e.Message;
                SwitchOff();
                if (StaticClass.proxys.Length - 1 >= bout + 1)
                {
                    startUp(bout + 1);
                }
            }
            return(false);
        }
コード例 #4
0
ファイル: Proxy.cs プロジェクト: zgcwkj/TestBaiduPassword
        public Proxy()
        {
            InitializeComponent();
            //记录Goto的次数
            int i = 0;

            //Goto 重新获取IP启动代理服务
Retry:
            //关闭代理服务
            if (httpProxy.GetSwitchState())
            {
                httpProxy.SwitchOff();
            }

            i++;
            if (i > 10)
            {
                MessageBox.Show("很抱歉程序暂时无法使用");
                Application.Exit();
            }

            string ip = httpProxy.GetProxyIp();

            //通过API获取代理数据
            try
            {
                if (!File.Exists(StaticClass.proxy))
                {
                    ObtainIP();
                }
                if (File.ReadAllText(StaticClass.proxy) == "")
                {
                    ObtainIP();
                }
                if (File.ReadAllText(StaticClass.proxy) == "\r\n")
                {
                    ObtainIP();
                }

                string   proxy  = File.ReadAllText(StaticClass.proxy);
                string[] proxys = proxy.Replace("\r", "").Split('\n');
                ip = proxys[0];

                File.Delete(StaticClass.proxy);
                File.AppendAllText(StaticClass.proxy, proxy.Replace(ip + "\r\n", ""));
            }
            catch (Exception e)
            {
                string str = e.Message;
            }

            httpProxy.SwitchOn(ip);

            try
            {
                txt_1.Text = ip;
                HttpHelp.HttpGet("https://blog.zgcwkj.top");
                Close();
            }
            catch (Exception e)
            {
                string str = e.Message;
                httpProxy.SwitchOff();
                //Goto 重试
                goto Retry;
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: zgcwkj/TestBaiduPassword
        /// <summary>
        /// 程序服务验证
        /// </summary>
        /// <returns></returns>
        private static bool ServiceVerificat()
        {
            //返回的状态
            bool status = false;

            try
            {
                new HttpProxy().SwitchOff();
                string   Serve  = HttpHelp.HttpGet("http://www.zgcwkj.top/TestPassword/Serve.txt");
                string[] Serves = Serve.Replace("\r", "").Split('\n');

                #region 更新模块

                if (Serves.Length >= 1)
                {
                    if (Serves[0] != "")
                    {
                        string[] Update = Serves[0].Split('|');
                        //是否强制更新
                        if (Convert.ToBoolean(Update[0]))
                        {
                            //匹配版本号进行判断
                            int versions = Convert.ToInt32(Application.ProductVersion.Replace(".", ""));
                            if (versions < Convert.ToInt32(Update[1]))
                            {
                                //提示更新内容
                                MessageBox.Show(Update[2]);
                                //通过浏览器跳转
                                try { System.Diagnostics.Process.Start(Update[3]); } catch { }
                                //直接终止程序运行
                                return(false);
                            }
                        }
                    }
                }

                #endregion 更新模块

                #region  序状态

                if (Serves.Length >= 2)
                {
                    if (Serves[1] != "")
                    {
                        //程序状态
                        if (Convert.ToBoolean(Serves[1]))
                        {
                            status = true;
                        }
                    }
                }

                #endregion  序状态

                #region 提示内容

                if (Serves.Length >= 3)
                {
                    if (Serves[2] != "")
                    {
                        //提示消息内容
                        MessageBox.Show(Serves[2]);
                    }
                }

                #endregion 提示内容

                #region 浏览器跳转

                if (Serves.Length >= 4)
                {
                    if (Serves[3] != "")
                    {
                        //通过浏览器跳转
                        try { System.Diagnostics.Process.Start(Serves[3]); } catch { }
                    }
                }

                #endregion 浏览器跳转
            }
            catch (Exception e)
            {
                string str = e.Message;
                MessageBox.Show("请检查网络状态");
                status = false;
            }
            return(status);
        }