|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using Network;
using Ping = Network.Ping;
namespace PingConsole
{
class Program
{
static void Main(string[] args)
{
DoPing().Wait(); ;
Console.WriteLine("All done");
Console.Read();
}
private static async Task DoPing()
{
var Ips = Enumerable.Range(188, 2)
.Select(nr => "192.168." + nr.ToString())
.SelectMany(net => Enumerable.Range(0, 254).Select(nr => net + "." + nr.ToString()));
var cts = new CancellationTokenSource();
var tasks = Ips
.Select(Network.Ping.ResolveAddress)
.Select(ip => Ping.ContinuousPingAsync(ip, 500, 1000, new Progress<PingResult>(PrintResult), cts.Token));
cts.CancelAfter(30000);
await Task.WhenAll(tasks);
}
private static void PrintResult(PingResult result)
{
if (result.LastStatus == IPStatus.Success)
Console.WriteLine("{0,-15}: ({1}/{2}) {3:fff}ms", result.Address, result.PingsSuccessfull, result.PingsTotal, result.AverageTime);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Peter Butzhammer studied physics but decided to work as a software developer 10 years ago. He has a strong interest in statistics, simulation and functional programming.