Exemple #1
0
        public static bool CheckProxy(PROXY_DATA proxyData)
        {
            bool flag = false;

            try
            {
                WebRequest request = WebRequest.Create("http://www.baidu.com");
                if (!proxyData.address.ToLower().StartsWith("http"))
                {
                    proxyData.address = "http://" + proxyData.address;
                }
                WebProxy proxy = new WebProxy {
                    Address = new Uri(proxyData.address)
                };
                if (proxyData.username != null)
                {
                    proxy.Credentials = new NetworkCredential(proxyData.username, proxyData.password);
                }
                request.Proxy   = proxy;
                request.Timeout = 5000;
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    return(true);
                }
                flag = false;
            }
            catch (Exception)
            {
            }
            return(flag);
        }
Exemple #2
0
        private void proxyTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            bool      flag              = false;
            ArrayList proxyDataList     = AppSettings.Instance.ProxyDataList;
            int       currentProxyIndex = this.currentProxyIndex;

            do
            {
                PROXY_DATA proxyData = BrowserSettings.GetProxyData((string)proxyDataList[currentProxyIndex]);
                logger.Info("proxy ip:" + proxyData.address);
                currentProxyIndex++;
                if (currentProxyIndex >= proxyDataList.Count)
                {
                    currentProxyIndex = 0;
                }
                if (this.SetProxy(proxyData))
                {
                    flag = true;
                    this.currentProxyIndex = currentProxyIndex;
                }
                else
                {
                    if (currentProxyIndex == this.currentProxyIndex)
                    {
                        this.Stop();
                        return;
                    }
                }
            }while (!flag);
        }
Exemple #3
0
        private bool SetProxy(PROXY_DATA proxyData)
        {
            bool flag = false;

            try
            {
                INTERNET_PROXY_INFO internet_proxy_info;
                if (!CheckProxy(proxyData))
                {
                    return(flag);
                }
                internet_proxy_info.dwAccessType    = 3;
                internet_proxy_info.lpszProxy       = Marshal.StringToHGlobalAnsi(proxyData.address);
                internet_proxy_info.lpszProxyBypass = Marshal.StringToHGlobalAnsi("local");
                IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(internet_proxy_info));
                Marshal.StructureToPtr(internet_proxy_info, ptr, true);
                flag = InternetSetOption(IntPtr.Zero, 0x26, ptr, Marshal.SizeOf(internet_proxy_info));
                if ((proxyData.username != null) && (proxyData.password != null))
                {
                    this.authRequired = true;
                    this.username     = proxyData.username;
                    this.pwd          = proxyData.password;
                }
                else
                {
                    this.authRequired = false;
                }
                InternetSetOption(IntPtr.Zero, 0x27, IntPtr.Zero, 0);
                InternetSetOption(IntPtr.Zero, 0x25, IntPtr.Zero, 0);
            }
            catch (Exception)
            {
            }
            return(flag);
        }
Exemple #4
0
        private void importBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog
            {
                DefaultExt       = "txt",
                Filter           = "TXT file (*.txt)|*.txt|CSV file (*.csv)|*.csv| All files (*.*)|*.*",
                AddExtension     = true,
                RestoreDirectory = true
            };

            try
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    foreach (string str2 in File.ReadAllText(dialog.FileName).Replace("\r", "").Split(new char[] { ',', ';', '\n', ' ' }))
                    {
                        if (str2 != "")
                        {
                            PROXY_DATA proxyData = GetProxyData(str2);
                            this.listBoxProxy.Items.Add(proxyData.address);
                            this.listBoxProxy.Items[this.listBoxProxy.Items.Count - 1].Tag = str2;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }
Exemple #5
0
 public void Start()
 {
     if (AppSettings.Instance.ProxyEnabled)
     {
         if (!AppSettings.Instance.ProxyRotate)
         {
             PROXY_DATA proxyData = BrowserSettings.GetProxyData((string)AppSettings.Instance.ProxyDataList[0]);
             this.SetProxy(proxyData);
         }
         else
         {
             this.proxyTimer          = new System.Timers.Timer();
             this.proxyTimer.Elapsed += new ElapsedEventHandler(this.proxyTimer_Elapsed);
             this.proxyTimer.Interval = (AppSettings.Instance.ProxyRotateInterval * 60) * 1000;
             this.proxyTimer_Elapsed(this, null);
             this.proxyTimer.Start();
         }
     }
 }
Exemple #6
0
        public static PROXY_DATA GetProxyData(string proxyDataString)
        {
            PROXY_DATA proxy_data = new PROXY_DATA();

            string[] strArray = proxyDataString.Split(new char[] { ' ', '\t' });
            if (strArray.Length > 1)
            {
                proxy_data.address = strArray[0] + ":" + strArray[1];
            }
            //if (strArray.Length > 1)
            //{
            //    proxy_data.username = strArray[1];
            //}
            //if (strArray.Length > 2)
            //{
            //    proxy_data.password = strArray[2];
            //}
            return(proxy_data);
        }
Exemple #7
0
 private void LoadProxyPage()
 {
     try
     {
         var setting = AppSettings.Instance;
         this.checkBoxEnableProxy.Checked = setting.ProxyEnabled;
         if (setting.ProxyDataList != null)
         {
             foreach (string str in setting.ProxyDataList)
             {
                 PROXY_DATA proxyData = GetProxyData(str);
                 this.listBoxProxy.Items.Add(proxyData.address);
                 this.listBoxProxy.Items[this.listBoxProxy.Items.Count - 1].Tag = str;
             }
         }
         this.checkBoxRotateProxy.Checked = setting.ProxyRotate;
         this.textBoxInterval.Text        = setting.ProxyRotateInterval.ToString();
     }
     catch (Exception)
     {
     }
 }