private async Task <bool> PingNetworkRange() { bool result = false; var current = IpStart.GetAddressBytes(); var end = IpEnd.GetAddressBytes(); List <Task <PingReply> > pingTasks = new List <Task <PingReply> >(); List <IPAddress> list = new List <IPAddress>(); await Task.Run(() => { foreach (byte secondPart in Enumerable.Range(current[1], end[1] - current[1] + 1)) { foreach (byte thirdPart in Enumerable.Range(current[2], end[2] - current[2] + 1)) { foreach (byte fourthPart in Enumerable.Range(current[3], end[3] - current[3] + 1)) { var ip = new IPAddress(new byte[] { current[0], secondPart, thirdPart, fourthPart }); pingTasks.Add(Ping(ip)); } } } Task.WaitAll(pingTasks.ToArray()); foreach (var pingTask in pingTasks) { if (pingTask.Result.Status == IPStatus.Success) { list.Add(pingTask.Result.Address); } } }); IpFoundList = list; return(result); }
/// <summary> /// Compare Method for comparing existing Ip addresses cached in memory. /// </summary> /// <value>int</value> public int CompareTo(object obj) { if (obj == null) { return(0); } return(IpStart.CompareTo(((IpCity)obj).IpStart)); }
public int CompareTo(object obj) { return(IpStart.CompareTo(((IpCity)obj).IpStart)); }