// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Diagnostics; using System.IO; using System.Threading; namespace E { public class MainClass { private const int NHOST = 256; public static void Main(string[] args) { Pinger[] p = new Pinger[NHOST]; Thread[] t = new Thread[NHOST]; for(int i = 0; i < NHOST; i++) { p[i] = new Pinger(i); t[i] = new Thread(new ThreadStart(p[i].Run)); t[i].Start(); } for(int i = 0; i < NHOST; i++) { t[i].Join(); Console.WriteLine(p[i].Res); } } } public class Pinger { private int no; private string res; public Pinger(int no) { this.no = no; res = ""; } public void Run() { ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "ping"; psi.Arguments = "192.168.0." + no; psi.CreateNoWindow = true; psi.UseShellExecute = false; psi.RedirectStandardOutput = true; Process p = Process.Start(psi); StreamReader sr = p.StandardOutput; string line; while((line = sr.ReadLine()) != null) { res += line; } sr.Close(); p.Close(); } public string Res { get { return res; } } } }