Exemplo n.º 1
0
 private void fillCollection(byte[] ip1, byte[] ip2)
 {
     for (UInt32 n = BitConverter.ToUInt32(ip1.Reverse().ToArray(), 0) + 1; n <= BitConverter.ToUInt32(ip2.Reverse().ToArray(), 0) - 1; n++)
     {
         string ipstr = new System.Net.IPAddress(BitConverter.GetBytes(n).Reverse().ToArray()).ToString();
         DeviceInfo d = new DeviceInfo(ipstr);
         _dicDeviceInfo.Add(ipstr, d);
     }
 }
Exemplo n.º 2
0
        public List<DeviceInfo> GetDevices()
        {
            try
            {
                //for offline device, you could run arp -d to clear arp table first

                //0 Init all device
                InitIPDevice();

                //1 ping broadcast
                PingBroadCast();

                //2 first time get arp result
                GetARPInfo(false);

                //3 ping other ip not in arp table list
                foreach (String k in _dicDeviceInfo.Keys)
                {
                    DeviceInfo d = new DeviceInfo("");
                    d = _dicDeviceInfo[k];

                    if (!d.isFound)
                    {
                        _pingTasks.Add(d.PingAsync(d.IPAddr));
                    }

                    //4 record these device have pinged in arp table
                    if (_pingTasks.Count == 100)
                    {
                        Task.WaitAll(_pingTasks.ToArray());
                        GetARPInfo(true);
                    }
                }

                //5 record the last part devices
                Task.WaitAll(_pingTasks.ToArray());
                GetARPInfo(true);

                //watch.[Stop]()
                //Dim elapsedMs = watch.ElapsedMilliseconds
                //MessageBox.Show(elapsedMs.ToString)

                //return founded device
                foreach (DeviceInfo ddd in _dicDeviceInfo.Values)
                {
                    if (ddd.isFound)
                    {
                        _listfounddevice.Add(ddd);
                    }
                }

                return _listfounddevice;
            }
            catch (Exception e)
            {
                throw new Exception("Throw  'arp -a'   Error", e);
            }
        }