private void _myPing_PingCompleted(object sender, PingCompletedEventArgs e) { if (e.Reply.Status == IPStatus.Success) { string reply = e.Reply.Address.ToString(); if (computerInfo.Keys.Contains(reply)) { try { computerInfo[reply].machinename = Dns.GetHostEntry(IPAddress.Parse(reply)).HostName; computerInfo[reply].status = ComputerStatus.ON_LINE; Kii.Invoke(computerInfo[reply]); } catch (Exception err) { } } } }
public Dictionary <string, ComputerIpInfo> EnumComputers() { try { string bIp = GetLocalMachineIp(); if (null == bIp || 0 == bIp.Length) { return(computerInfo); } for (int i = 0; i <= 10; i++) { Ping myPing; myPing = new Ping(); myPing.PingCompleted += new PingCompletedEventHandler(_myPing_PingCompleted); string pingIP = bIp + i.ToString(); byte[] buffer = Encoding.ASCII.GetBytes(""); if (!computerInfo.Keys.Contains(pingIP)) { ComputerIpInfo cip = new ComputerIpInfo(); string mac = GetRemoteMac(localMachine.ip, pingIP); cip.ip = pingIP; cip.status = ComputerStatus.BREAK_LIEN; if (mac != "0") { cip.mac = mac; } computerInfo.Add(pingIP, cip); Kii.Invoke(cip); } myPing.SendAsync(pingIP, 1000, buffer); } } catch (Exception err) { } return(computerInfo); }
//显示配置属性 public void ShowForm(Soft st, int type) { Kii.Invoke(st, type); }