예제 #1
0
        /// <summary>
        /// Поиск свободных адресов.
        /// </summary>
        public void SearchFreeAddresses(SearchFreeAddressesParams searchParams)
        {
            foreach (var subnet in searchParams.Subnets)
            {
                if (String.IsNullOrWhiteSpace(subnet))
                {
                    continue;
                }

                for (int i = 1; i < 255; i++)
                {
                    string address = subnet + "." + i.ToString();

                    if (!ValidateIPAddress(address))
                    {
                        continue;
                    }

                    if (ExistsInDNS(address))
                    {
                        continue;
                    }

                    if (RepliesToPing(address))
                    {
                        continue;
                    }

                    searchParams.Dispatcher.BeginInvoke(searchParams.Callback, address);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Валидация параметров поиска свободных адресов.
        /// </summary>
        /// <returns>
        /// Объект SearchFreeAddressesParams - при успешной валидации.
        /// Null - при ошибке валидации.
        /// </returns>
        private SearchFreeAddressesParams ValidateAddressesSearchParams()
        {
            if (String.IsNullOrWhiteSpace(tbSubnets.Text))
            {
                ShowErrorMessage("Укажите хотя бы одну подсеть.");
                return(null);
            }

            var searchParams = new SearchFreeAddressesParams()
            {
                Subnets    = new List <string>(),
                Dispatcher = Dispatcher,
                Callback   = AddFreeAddress
            };

            searchParams.Subnets.AddRange(tbSubnets.Text.Replace("\r", "").Split('\n'));

            return(searchParams);
        }
예제 #3
0
 /// <summary>
 /// Асинхронный поиск свободных адресов.
 /// </summary>
 public Task SearchFreeAddressesAsync(SearchFreeAddressesParams searchParams)
 {
     return(Task.Factory.StartNew(() => SearchFreeAddresses(searchParams)));
 }