Exemple #1
0
 private void tbIpStart_TextChanged(object sender, EventArgs e)
 {
     if (tbIpStart.Text != "" && NetworkSetting.IsIPAddress(tbIpStart.Text))
     {
         string ipsegment = tbIpStart.Text.Substring(0, tbIpStart.Text.LastIndexOf('.'));
         tbIpEnd.Text   = ipsegment + ".253";
         tbGateWay.Text = ipsegment + ".254";
     }
 }
Exemple #2
0
        //后台投票
        private void thIpVote_DoWork()
        {
            string startIP = null;
            string endIP   = null;
            string gateway = null;
            string dns     = null;

            this.Invoke(new EventHandler(delegate
            {
                //开始轮询IP
                startIP = tbIpStart.Text;
                endIP   = tbIpEnd.Text;
                gateway = tbGateWay.Text;
                dns     = tbDNS.Text;
                if (!NetworkSetting.IsIPAddress(startIP) || !NetworkSetting.IsIPAddress(endIP) ||
                    !NetworkSetting.IsIPAddress(gateway) || !NetworkSetting.IsIPAddress(dns))
                {
                    MessageBox.Show("IP地址格式有误!");
                    btnIPVote_Click(null, null);
                    return;
                }
            }));
            int start = Convert.ToInt32(startIP.Split('.')[3]);
            int end   = Convert.ToInt32(endIP.Split('.')[3]);

            ipTotalCount = end - start + 1;
            if (flagRandomMode)
            {
                ipListMain = new List <int>(end - start + 1);
                for (int i = start; i <= end; i++)
                {
                    ipListMain.Add(i);
                }
            }
            string ipsegment = startIP.Substring(0, startIP.LastIndexOf('.'));

            ShowBusyUI(true);
            while (start <= end)
            {
                try
                {
                    if (flagRandomMode)
                    {
                        Random rand  = new Random(DateTime.Now.Millisecond);
                        int    index = rand.Next(end - start + 1);
                        ipCurrent = ipsegment + "." + ipListMain[index];
                        ipListMain.RemoveAt(index);
                    }
                    else
                    {
                        ipCurrent = ipsegment + "." + start;
                    }
                    if (ipCurrent == "211.69.198.23")//认证服务器的ip不要抢
                    {
                        continue;
                    }
                    NetworkSetting.SetIPAddress(ipCurrent, "255.255.255.0", gateway);
                    //...DNS默认不变
                    //NetworkSetting.SetDNS(new string[] { dns, "8.8.8.8" });
                    //Thread.Sleep(1000);
                    flagWaitForHttpResponse = true;
                    if (flagVoteHot)
                    {
                        //刷人气
                        VoteAddHot(3);
                    }
                    //tmTimeOut.Start();//
                    if (flagVote)
                    {
                        //刷票
                        VoteForOnce();
                    }
                    //刷新网站投票
                    thGetVoteShow_DoWork();
                    //Thread.Sleep(3000);
                    //while (flagWaitForHttpResponse)
                    //{
                    //    Thread.Sleep(200);
                    //}
                    if (!flagIpVoteStart)
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    OutMsg(ipCurrent + "投票异常:" + ex.Message);
                }
                finally
                {
                    start++;
                    ipTestedCount++;
                    this.Invoke(new EventHandler(delegate
                    {
                        lbIpVoteCountState.Text = ipTestedCount.ToString() + "/" + ipTotalCount.ToString();
                    }));
                }
                //两次投票之间休眠一段时间
                Random randTime  = new Random(DateTime.Now.Millisecond);
                int    sleeptime = randTime.Next(1000, 5000);
                OutMsg("休眠" + sleeptime + "ms");
                Thread.Sleep(sleeptime);
            }
            this.Invoke(new EventHandler(delegate
            {
                OutMsg("本次投票成功:" + succCount + "次,投票失败:" + failCount + "次");
                btnIPVote.Enabled = true;
            }));
            ShowBusyUI(false);
            SetIpVoteBtnState(false);

            if (flagOnceMore)
            {
                tbIpStart.Text = tbBeiStartIP.Text;
                tbIpStart_TextChanged(null, null);
                btnIPVote_Click(null, null);
                flagOnceMore = false;
            }
            else
            {
                tbIpStart.Text = "211.69.198.1";
                tbIpStart_TextChanged(null, null);
                //恢复原始IP
                RestoreOriginIP();
            }
        }