public static List <Computer> GetServerRangeTargets(int count) { List <Task> tasklist = new List <Task>(); Console.WriteLine("[*] Obtaining random server targets ..."); List <Computer> targets = new List <Computer>(); List <IPAddress> ips = new List <IPAddress>(); List <Computer> dcs = Ldap.GetDcs(); Random random = new Random(); int index = random.Next(dcs.Count); IPAddress dc = IPAddress.Parse(dcs[index].IPv4); Console.WriteLine("[*] Wrandomly picked DC {0}", dcs[index].Fqdn); ips = Lib.Networking.GetRange(dc, 24, count); foreach (IPAddress ip in ips) { tasklist.Add(Task.Factory.StartNew(() => { TimeSpan interval = TimeSpan.FromSeconds(3); if (Lib.Networking.OpenPort(ip.ToString(), 445, interval)) { //Console.WriteLine("trying to resolve " + ip.ToString()); string hostname = Lib.Networking.ResolveIp(ip); if (hostname != "") { Computer newhost = new Computer(); newhost.Fqdn = hostname; newhost.IPv4 = ip.ToString(); targets.Add(newhost); //Console.WriteLine("Found " + hostname); } } })); } Task.WaitAll(tasklist.ToArray()); return(targets); }