概述
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.Net.Sockets;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private static int i1, i2, i3, i4,d1;
private void button1_Click(object sender, EventArgs e)
{
try
{
this.listView1.Clear();
this.listView1.Columns.Add("IP", 100, HorizontalAlignment.Left);
this.listView1.Columns.Add("主机名", 180, HorizontalAlignment.Left);
i1 = int.Parse(this.textBox1.Text);
i2 = int.Parse(this.textBox2.Text);
i3 = int.Parse(this.textBox3.Text);
i4 = int.Parse(this.textBox4.Text);
d1 = int.Parse(textBox9.Text);
if (i1 >= 255 || i2 >= 255 || i3 >= 255 || i4 >= 255)
{
MessageBox.Show("你的开始IP 有误");
return;
}
else
{
this.progressBar1.Maximum = int.Parse(this.textBox9.Text);
this.progressBar1.Value = 1;
strat();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.listView1.Columns.Add("IP", 100, HorizontalAlignment.Left);
this.listView1.Columns.Add("主机名", 180, HorizontalAlignment.Left);
}
private void strat()
{
Thread[] thread = new Thread[d1];
int s = d1 - 1;
while (true)
{
thread[s] = new Thread(new ThreadStart(dowhlies));
thread[s].Start();
s--;
if (s == 0)
break;
}
}
private string ips()
{
lock (this)
{
i4++;
if (i4 == 254)
{
i4 = 1;
i3++;
}
else if (i3 == 254)
{
i3 = 0;
i2++;
}
else if (i2 == 254)
{
i2 = 0;
i1++;
}
return i1.ToString() + "." + i2.ToString() + "." + i3.ToString() + "." + i4.ToString();
}
}
private int d = 0;
private int s = 0;
private void dowhlies()
{
string dis= ips();
string ds = "";
try
{
IPHostEntry results = Dns.GetHostByAddress(dis);
ds = results.HostName;
d=d+1;
label4.Text = "有" + d.ToString() + "主机获取主机名成功..";
}
catch (Exception ex)
{
s = s + 1;
ds = ex.Message;
label5.Text = "有" + s.ToString() + "主机获取主机名失败..";
}
ListViewItem l1 = new ListViewItem();
// this.listView1.Items.Add(i1.ToString() + "." + i2.ToString() + "." + i3.ToString() + "." + i4.ToString());
l1.SubItems[0].Text = dis;
l1.SubItems.Add(ds);
this.listView1.Items.Add(l1);
this.listView1.Update();
this.progressBar1.Value++;
}
private void button2_Click(object sender, EventArgs e)
{
this.listView1.Clear();
this.d = 0;
this.s=0;
}
}
}
最后
以上就是专一裙子为你收集整理的c# 很久以前写的 HOST 获取工具 速度快一流的的全部内容,希望文章能够帮你解决c# 很久以前写的 HOST 获取工具 速度快一流的所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复