C#获取局域网IP地址

时间:2016-09-22 09:00:46
【文件属性】:

文件名称:C#获取局域网IP地址

文件大小:560B

文件格式:TXT

更新时间:2016-09-22 09:00:46

获取IP地址

获取局域网内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); } }


网友评论