private void button1_Click(object sender, EventArgs e) { button1.Enabled = false; button2.Enabled = false; button3.Enabled = false; listView1.Items.Clear(); ip ipEnum = new ip(); int num1 = ipEnum.IPToNumber(textBox1.Text); int num2 = ipEnum.IPToNumber(textBox2.Text); progressBar1.Minimum = 0; progressBar1.Maximum = Program.totalCount = num2 - num1 + 1; Program.scannedCount = 0; var lst = new TaskList(); for (int i = num1; i <= num2; i++) { string strIP = ipEnum.NumberToIP(i); var NewTask = new Action(() => { //Console.WriteLine(string.Format("第{0}个任务(用时{1}秒)已经开始", j, s)); //Thread.Sleep(s * 1000); //Console.WriteLine(string.Format("第{0}个任务(用时{1}秒)已经结束", j, s)); pingIP(strIP); }); lst.Tasks.Add(NewTask); //progressBar1.Value = i-num1; } lst.Start(); }
private void AddListItem(ListViewItem str) { this.listView1.Items.Add(str); ip ipEnum = new ip(); //int barMax = Math.Abs(ipEnum.IPToNumber(textBox2.Text) - ipEnum.IPToNumber(textBox1.Text)); int barMax = Program.totalCount; if (Program.scannedCount == barMax) { button1.Enabled = true; TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress); button2.Enabled = true; button3.Enabled = true; } else { TaskbarProgress.SetValue(this.Handle, Program.scannedCount, barMax); } progressBar1.Value = Program.scannedCount; }
private void pingIP(string strIP) { ip ipEnum = new ip(); ListViewItem lvi = new ListViewItem(); lvi.Text = strIP; lvi.Font = new Font("微软雅黑", 11, FontStyle.Regular); string retPing = ipEnum.ping(strIP); if (retPing != "超时") { try { IPHostEntry myscanhost = Dns.GetHostEntry(strIP); string strHost = myscanhost.HostName.ToString(); lvi.SubItems.Add(strHost); } catch { lvi.SubItems.Add(""); } } else { lvi.SubItems.Add(""); } //添加其他栏目 lvi.SubItems.Add(retPing); lvi.SubItems.Add(""); lvi.SubItems.Add(""); lvi.SubItems.Add(""); lvi.SubItems.Add(""); lvi.SubItems.Add(""); lvi.SubItems.Add(""); Program.scannedCount++; SetListItem(lvi); }