private void SetDefaultAddressRange()
        {
            var hostIp     = Network_Functions.GetHostIP();
            var hostSubnet = Network_Functions.GetSubnetMask(hostIp);

            if (hostIp != null && hostSubnet != null)
            {
                var ipNetwork = IPNetwork.Parse(hostIp, hostSubnet);
                if (ipNetwork != null)
                {
                    var ips = IPNetwork.ListIPAddress(ipNetwork).ToList();
                    if (ips != null && ips.Count > 0)
                    {
                        StartAddress = ips[0].ToString();
                        EndAddress   = ips[ips.Count - 1].ToString();
                    }
                }
            }
        }
        private IPAddress[] GetAddressRange()
        {
            var hostIp     = Network_Functions.GetHostIP();
            var hostSubnet = Network_Functions.GetSubnetMask(hostIp);

            if (hostIp != null && hostSubnet != null)
            {
                var ipNetwork = IPNetwork.Parse(hostIp, hostSubnet);
                if (ipNetwork != null)
                {
                    var ips = IPNetwork.ListIPAddress(ipNetwork).ToList();
                    if (ips != null && ips.Count > 0)
                    {
                        // Get Start Address
                        IPAddress start = null;
                        IPAddress.TryParse(StartAddress, out start);

                        // Get End Address
                        IPAddress end = null;
                        IPAddress.TryParse(EndAddress, out end);

                        if (start != null && end != null)
                        {
                            var range = new Network_Functions.IPAddressRange(start, end);
                            addressRange = ips.FindAll(o => range.IsInRange(o));

                            // Set HostIp to LocalHost instead of using network IP
                            int localhostIndex = addressRange.FindIndex(o => o.ToString() == hostIp.ToString());
                            if (localhostIndex >= 0)
                            {
                                addressRange[localhostIndex] = IPAddress.Loopback;
                            }

                            return(addressRange.ToArray());
                        }
                    }
                }
            }

            return(null);
        }
        public void FindDevices()
        {
            DevicesLoading      = true;
            DevicesAlreadyAdded = 0;
            DevicesNotAdded     = 0;
            NetworkNodesFound   = 0;
            nodesChecked        = 0;
            DeviceInfos.Clear();
            addressRange = null;
            LogItems.Clear();

            pingTimeout = PingTimeout;

            var hostIp     = Network_Functions.GetHostIP();
            var hostSubnet = Network_Functions.GetSubnetMask(hostIp);

            if (hostIp != null && hostSubnet != null)
            {
                var ipNetwork = IPNetwork.Parse(hostIp, hostSubnet);
                if (ipNetwork != null)
                {
                    var ips = IPNetwork.ListIPAddress(ipNetwork).ToList();
                    if (ips != null && ips.Count > 0)
                    {
                        // Get Start Address
                        IPAddress start = null;
                        IPAddress.TryParse(StartAddress, out start);

                        // Get End Address
                        IPAddress end = null;
                        IPAddress.TryParse(EndAddress, out end);

                        if (start != null && end != null)
                        {
                            AddtoLog(LogType.INFO, "Starting Auto Detect..");
                            AddtoLog(LogType.INFO, "IP Address Range : From " + start.ToString() + " to " + end.ToString());
                            AddtoLog(LogType.INFO, "Port Range : From " + portRangeStart.ToString() + " to " + portRangeStop.ToString());

                            var range = new Network_Functions.IPAddressRange(start, end);

                            addressRange = ips.FindAll(o => range.IsInRange(o));

                            int localhostIndex = addressRange.FindIndex(o => o.ToString() == hostIp.ToString());
                            if (localhostIndex >= 0)
                            {
                                addressRange[localhostIndex] = IPAddress.Loopback;
                            }
                        }
                    }
                }
            }

            portRangeStart = StartPort;
            portRangeStop  = EndPort;

            SearchProgressValue   = 0;
            SearchProgressMaximum = 0;

            stop = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem(new WaitCallback(FindDevices_Worker));
        }