/// <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); } } }
/// <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); }
/// <summary> /// Асинхронный поиск свободных адресов. /// </summary> public Task SearchFreeAddressesAsync(SearchFreeAddressesParams searchParams) { return(Task.Factory.StartNew(() => SearchFreeAddresses(searchParams))); }