Esempio n. 1
0
        private static ModelHost ReadAddresses(byte[] data)
        {
            byte[] hwAddress = new byte[6];
            byte[] ipAddress = new byte[4];
            uint   hwOffset  = 22;
            uint   ipOffset  = 28;

            for (int i = 0; i < 6; i++)
            {
                hwAddress[i] = data[hwOffset + i];
            }
            for (int i = 0; i < 4; i++)
            {
                ipAddress[i] = data[ipOffset + i];
            }
            string    hwAddr = NetworkHelper.getPhysicalAddressStringFromArp(hwAddress);
            IPAddress ipAddr = new IPAddress(ipAddress);
            string    _name  = TryGetName(ipAddr);
            ModelHost _tmp;

            if (String.IsNullOrEmpty(_name))
            {
                _tmp = new ModelHost(hwAddr, ipAddr);
            }
            else
            {
                _tmp = new ModelHost(hwAddr, ipAddr, _name);
            }
            return(_tmp);
        }
Esempio n. 2
0
 public static void RemoveFromList(ModelHost dummy)
 {
     if (Exists(dummy))
     {
         lock (lockObj)
         {
             DecreaseCount();
             hostList.Remove(hostList.Find(x => x.hostMac.Contains(dummy.hostMac)));
         }
     }
 }
Esempio n. 3
0
 public static void AddToList(ModelHost dummy)
 {
     lock (lockObj)
     {
         hostList.Add(dummy);
         if (!Exists(dummy))
         {
             IncreaseCount();
         }
     }
 }
Esempio n. 4
0
 private static void SyncModelHosts(ModelHost _dummy)
 {
     if (ModelHost.Exists(_dummy))
     {
         ModelHost.UpdateHost(_dummy, _dummy);
     }
     else
     {
         ModelHost.AddToList(_dummy);
     }
 }
Esempio n. 5
0
 public static void AddToList(string macAddr, IPAddress ipAddr, string hostName)
 {
     lock (lockObj)
     {
         ModelHost _dummy = new ModelHost(macAddr, ipAddr, hostName);
         hostList.Add(_dummy);
         if (!Exists(_dummy))
         {
             IncreaseCount();
         }
     }
 }
Esempio n. 6
0
 public static void AddToList(string macAddr)
 {
     lock (lockObj)
     {
         ModelHost _dummy = new ModelHost(macAddr);
         hostList.Add(_dummy);
         if (!Exists(_dummy))
         {
             IncreaseCount();
         }
     }
 }
Esempio n. 7
0
 public static void UpdateHost(ModelHost dummy, ModelHost replacement)
 {
     lock (lockObj)
     {
         if (Exists(dummy))
         {
             RemoveFromList(dummy);
             AddToList(replacement);
         }
         else
         {
             AddToList(replacement);
         }
     }
 }
Esempio n. 8
0
 public static void UpdateHost(ModelHost dummy, IPAddress ipAddr, string hostName)
 {
     lock (lockObj)
     {
         if (Exists(dummy))
         {
             RemoveFromList(dummy);
             AddToList(dummy.hostMac, ipAddr, hostName);
         }
         else
         {
             AddToList(dummy.hostMac, ipAddr, hostName);
         }
     }
 }
Esempio n. 9
0
 public static void UpdateHost(string macAddr, ModelHost replacement)
 {
     lock (lockObj)
     {
         if (Exists(macAddr))
         {
             RemoveFromList(macAddr);
             AddToList(replacement);
         }
         else
         {
             AddToList(replacement);
         }
     }
 }
Esempio n. 10
0
        public static bool Exists(ModelHost dummy)
        {
            bool _exists;

            if (dummy.hostMac == null)
            {
                return(false);
            }

            var _foo = hostList.Find(x => x.hostMac.Contains(dummy.hostMac));

            if (_foo == null)
            {
                _exists = false;
            }
            else
            {
                _exists = true;
            }

            return(_exists);
        }
Esempio n. 11
0
 private static void ProcessCheck(object sender, CaptureEventArgs packet)
 {
     if (packet.Packet.Data.Length >= 42)
     {
         byte[]    data      = packet.Packet.Data;
         byte[]    arpheader = new byte[4];
         ModelHost _dummy    = new ModelHost();
         arpheader[0] = data[12];
         arpheader[1] = data[13];
         arpheader[2] = data[20];
         arpheader[3] = data[21];
         if (arpheader[0] == 8 && arpheader[1] == 6 && arpheader[2] == 0 && arpheader[3] == 2)
         {
             _dummy = ReadAddresses(data);
         }
         if (ModelHost.Exists(_dummy))
         {
             _dummy.status = true;
             ModelHost.UpdateHost(_dummy, _dummy);
         }
     }
 }
Esempio n. 12
0
        private void ProcessData()
        {
            try
            {
                if (NetworkHelper.IsDhcp(_data) && NetworkHelper.IsDhcpRequest(_data))
                {
                    ModelHost _tmpModel = new ModelHost();
                    _tmpModel.hostMac  = NetworkHelper.getPhysicalAddressStringFromDhcp(_data);
                    _tmpModel.macGiven = true;

                    for (uint i = NetworkHelper.DHCP_COOKIE_POSITION; i < _data.Length; i++)
                    {
                        switch (Convert.ToUInt16(_data[i]))
                        {
                        case 50:
                            byte[] _ipBytes = new byte[4];

                            for (uint ii = 0; ii < 4; ii++)
                            {
                                _ipBytes[ii] = _data[i + 2 + ii];
                            }

                            _tmpModel.ipGiven = true;
                            _tmpModel.hostIP  = new IPAddress(_ipBytes);

                            continue;

                        case 55:
                            i = 1 + i + _data[i + 1];

                            continue;

                        case 12:

                            byte _nameLength = _data[i + 1];
                            _tmpModel.hostName = "";
                            try
                            {
                                for (uint iii = 1; iii <= _nameLength; iii++)
                                {
                                    _tmpModel.hostName += (char)_data[i + 1 + iii];
                                    _tmpModel.nameGiven = true;
                                }
                            }
                            catch
                            {
                            }
                            continue;

                        default:

                            break;
                        }
                    }

                    if (ModelHost.Exists(_tmpModel))
                    {
                        if (_tmpModel.nameGiven)
                        {
                            ModelHost.UpdateHost(_tmpModel, _tmpModel.hostIP, _tmpModel.hostName);
                        }
                        else
                        {
                            ModelHost.UpdateHost(_tmpModel, _tmpModel.hostIP);
                        }
                    }
                    else
                    {
                        ModelHost.AddToList(_tmpModel);
                    }

                    _js.SyncNodes(ModelHost.hostList);
                }
            }
            catch
            {
            }
        }