public static void ScanIP(int startIP, int endIP) { string IPAd = ""; NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adapter in adapters) { IPInterfaceProperties adapterProperties = adapter.GetIPProperties(); GatewayIPAddressInformationCollection addresses = adapterProperties.GatewayAddresses; if (addresses.Count > 0) { Console.WriteLine(adapter.Description); foreach (GatewayIPAddressInformation address in addresses) { Console.WriteLine(" Адрес шлюза: {0}", address.Address.ToString()); for (int i = 0, j = 0; i < address.Address.ToString().Length; i++) { if (j == 3 && address.Address.ToString()[i - 1] == '.') { break; } if (address.Address.ToString()[i] == '.') { j++; } if (j < 3) { IPAd += address.Address.ToString()[i]; } } } Console.WriteLine(); } } Console.WriteLine("Активные устройства в подсети:"); for (int i = startIP; i <= endIP; i++) { string ipnum = IPAd + "." + i; PingCheck pch = new PingCheck(ipnum); } Console.WriteLine("Сканирование завершено"); Console.WriteLine(); }
public static void ScanIP() { string IPAd = "0.0.0.0"; int FirstAd = 0; string lol = ""; //Поля, содержащие IP адрес и Хост: VarIS varIS = new VarIS(); //Вызываем метод show(): //string adressA = ""; Console.WriteLine("Шлюзы:"); NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adapter in adapters) { IPInterfaceProperties adapterProperties = adapter.GetIPProperties(); GatewayIPAddressInformationCollection addresses = adapterProperties.GatewayAddresses; if (addresses.Count > 0) { Console.WriteLine(adapter.Description); foreach (GatewayIPAddressInformation address in addresses) { Console.WriteLine(" Адрес шлюза: {0}", address.Address.ToString()); IPAd = ""; for (int i = 0, j = 0; i < address.Address.ToString().Length; i++) { if (address.Address.ToString()[i] == '.') { j++; } if (j == 3) { i++; } if (j < 3) { IPAd += address.Address.ToString()[i]; } else { lol += address.Address.ToString()[i]; } } } Console.WriteLine(IPAd); Console.WriteLine(lol); } } Console.WriteLine("Активные устройства в подсети:"); for (int i = Convert.ToInt32(FirstAd); i <= Convert.ToInt32(FirstAd) + 15; i++) { if (varIS.isBreak) { varIS.isBreak = false; break; } string ipnum = IPAd + '.' + i; PingCheck pch = new PingCheck(ipnum); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Сканирование завершено"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(); }