public static IPAddress[] GetAllHostsWithOpenPort(IPAddress start, IPAddress end)
{
ConsoleColor c = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Yellow;
uint from = IPAddressToUInt(start);
uint to = IPAddressToUInt(end);
uint between = to - from;
string title = Console.Title;
List<IPAddress> list = new List<IPAddress>();
for (uint i = from; i <= to; i++)
{
Console.Title = ((double)i / between * 100) + "% | " + i;
string[] temp = new IPAddress(i).ToString().Split('.');
string[] newTemp = { temp[3], temp[2], temp[1], temp[0] };
IPAddress ip = IPAddress.Parse(string.Join(".", newTemp));
try
{
TcpClient client = new TcpClient();
client.BeginConnect(ip, Port, new AsyncCallback(CallBack), client);
}
catch (SocketException) // no such host | port closed | port busy
{
//Console.WriteLine("{0}:{1} is not ready for your commands", ip.ToString(), Port);
}
}
Console.Title = title;
System.Threading.Thread.Sleep(5000);
Console.ForegroundColor = c;
return list.ToArray();
}