获取局域网内IP地址的方法:
private void EnumComputers()
{
try
{
for (int i = 1; i <= 255; i++)
{
Ping myPing;
myPing = new Ping();
myPing.PingCompleted += new PingCompletedEventHandler(_myPing_PingCompleted);
string pingIP = "192.168.1." + i.ToString();
myPing.SendAsync(pingIP, 1000, null);
}
}
catch
{
}
}
private void _myPing_PingCompleted(object sender, PingCompletedEventArgs e)
{
string rsl = e.Reply.Address.ToString();
if (e.Reply.Status == IPStatus.Success)
{
rsl += " " + GetMacAddress(e.Reply.Address.ToString());
this.listBox1.Items.Add(rsl);
}
}