public static void Main(string[] args) { try { Console.WriteLine("IP PINGER"); Console.Write("Start ip: "); IPParser startPoint = new IPParser(IPAddress.Parse(Console.ReadLine())); Console.Write("End ip: "); IPParser endPoint = new IPParser(IPAddress.Parse(Console.ReadLine())); Console.WriteLine("\nPinging all ips . . .\n"); Console.WriteLine("-------------Alive IPs-------------"); while (startPoint.GreaterOrEqual(endPoint)) { Thread pinger = new Thread(() => PingerThread(startPoint.GetCopy().IPAddress)); pinger.Start(); Thread.Sleep(5); startPoint.Inc(); } while (ThreadCount > 0) { } Console.WriteLine("\n--------------END----------------"); Console.ReadKey(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void SendPing(Action <PingSuccess> onPingSuccessCallback, Action <PingFailure> onPingFailureCallback, int numberOfSeparatePings = 10, int timeOutMilliseconds = 5000) { if (numberOfSeparatePings < 1) { throw new ArgumentException("Must be at least one", nameof(numberOfSeparatePings)); } CancelPendingPings(); ClearPingResponseStuff(); PingSuccessCallback = onPingSuccessCallback; PingFailureCallback = onPingFailureCallback; Task.Run(() => { // We run this on another thread because if an invalid hostname is provided it takes literally five entire seconds // for .net to figure that out. F**k you .net if (TargetAddress == null) { try { TargetAddress = IPParser.ParseAddress(HostNameOrAddress); } catch { TriggerPingFailure(PingFailureReason.AddressNotFound); return; } } if (TargetAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) { // Sorry about this... Mono's Ping() doesn't support IPv6. I tried to add support (see the 'fixedping' branch) but // Unity's Mono fork has a bug where you can't create IPv6 ICMP sockets. This bug is *not* present on upstream // Mono. I've reported the bug to Unity, as soon as they fix it I should be able to add IPv6 suport to this class. TriggerPingFailure(PingFailureReason.IPv6NotSupported); return; } for (int i = 0; i <= numberOfSeparatePings; i++) { var ping = new Ping(); IndividualPings.Add(ping); ping.PingCompleted += OnPingCompleted; } // Send the pings *after* they've all been created, to make absolutely certain that we recieve no ping responses until // we know how many responses are expected. This has actually happened to me a couple of times when pinging localhost, // though it's pretty rare. lock (IndividualPings.__InternalListLock) { foreach (var ping in IndividualPings) { ping.SendAsync(TargetAddress, timeOutMilliseconds, null); } } }); }
public object EvalRight(string rvalue) { var result = ParseTypes(rvalue); if (result != null) { return(result); } return(IPParser.Count(rvalue)); }
internal async Task AddToWhitelistAsync(IEnumerable <string> whitelist) { if (whitelist?.Any() != true) { return; } foreach (var address in whitelist) { var addressees = await IPParser.Parse(address).ConfigureAwait(false); _whitelist.AddRange(addressees.Where(x => !_whitelist.Contains(x))); } }
internal async Task AddToWhitelistAsync(IEnumerable <string>?whitelist) { if (whitelist?.Any() != true) { return; } foreach (var whiteAddress in whitelist) { var parsedAddresses = await IPParser.ParseAsync(whiteAddress).ConfigureAwait(false); foreach (var address in parsedAddresses.Where(x => !_whiteListBag.Contains(x))) { _whiteListBag.Add(address); } } }
public async Task IpParseCount_ReturnsCorrectValue(string address, int count) => Assert.AreEqual(count, (await IPParser.ParseAsync(address)).Count());
public async Task IpParseNotEmpty_ReturnsCorrectValue(string address) => CollectionAssert.IsNotEmpty(await IPParser.ParseAsync(address));
public void IsSimpleIPRange_ReturnsCorrectValue(string address, bool expectedResult) => Assert.AreEqual(expectedResult, IPParser.IsSimpleIPRange(address));
public void IsCIDRNotation_ReturnsCorrectValue(string address, bool expectedResult) => Assert.AreEqual(expectedResult, IPParser.IsCidrNotation(address));