各位DX:我有一个根据IP获得局域网内计算机名称的程序,但执行后速度太慢,请指点:
private void button1_Click(object sender, System.EventArgs e)
{
this.button1.Enabled=false;
string mystartIP="192.168.0.";
string myip;
int s,end;
string name,mymac;
for(s=1;s<=255;s++)
{
myip=mystartIP +s.ToString();
//转换IP地址
IPAddress myscanip=IPAddress.Parse(myip);
try
{
System.Windows.Forms.Application.DoEvents();
IPHostEntry myscanhost=Dns.GetHostByAddress(myscanip);
name=myscanhost.HostName.ToString();
this.listBox1.Items.Add(myip +" " +name);
}
catch(Exception myerror)
{
}
}
}
执行后,可以根据IP得到局域网中其他计算机的名称,但速度太慢,请指教!!