Beispiel #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";
     }
 }
Beispiel #2
0
 //恢复本机默认IP
 private void RestoreOriginIP()
 {
     //return;
     if (NetworkSetting.isDHCPEnabled())
     {
         NetworkSetting.EnableDHCP();
     }
     else
     {
         NetworkSetting.SetIPAddress(ipOrigin, "255.255.255.0", gatewayOrigin);
         //NetworkSetting.SetDNS(new string[] { dnsOrigin, "8.8.8.8" });
     }
 }
Beispiel #3
0
 public MainForm()
 {
     InitializeComponent();
     logFileStream = new FileStream("ipresult.log", FileMode.Append, FileAccess.Write);
     try
     {
         sw            = new StreamWriter(logFileStream);
         dnsOrigin     = NetworkSetting.GetDNS()[0].ToString();
         ipOrigin      = NetworkSetting.GetIP();
         gatewayOrigin = NetworkSetting.GetIPDefaultGateWay();
         cmbRankStart.SelectedIndex = 0;
         thGetVoteShow = new Thread(new ThreadStart(thGetVoteShow_DoWork));
         thGetVoteShow.IsBackground  = true;
         tmCheckSystemTime.Elapsed  += new System.Timers.ElapsedEventHandler(tmCheckSystemTime_Elapsed);
         tmCheckSystemTime.AutoReset = true;
         tmCheckSystemTime.Interval  = 60000;
         tmCheckSystemTime.Start();
     }
     catch (System.Exception ex)
     {
         MessageBox.Show("请检查网卡配置,是否有可用网卡?", "启动异常");
         //Application.Exit();
     }
 }
Beispiel #4
0
 private void btnIPVote_Click(object sender, EventArgs e)
 {
     if (!flagIpVoteStart)//进入刷票模式
     {
         if (NetworkSetting.isDHCPEnabled())
         {
             //MessageBox.Show();
             OutMsg("当前为DHCP模式,可能不支持!");
             //return;
         }
         succCount     = 0;
         failCount     = 0;
         ipTestedCount = 0;
         ipTotalCount  = 0;
         if (ipListMain != null)
         {
             ipListMain.Clear();
         }
         SetIpVoteBtnState(true);
         thIpVote = new Thread(new ThreadStart(thIpVote_DoWork));
         thIpVote.IsBackground = true;
         thIpVote.Start();
         OutMsg("开始刷票...");
     }
     else
     {
         if (sender != null)//手点的按钮,不再运行第二次
         {
             flagOnceMore = false;
         }
         //bw.CancelAsync();
         SetIpVoteBtnState(false);
         OutMsg("正在停止...");
         btnIPVote.Enabled = false;
     }
 }
Beispiel #5
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();
            }
        }