Bug in .NET Ping.Send method

Bug in .NET Ping.Send method.

Pinging addresses on LAN via C#
public static class NetworkScanner {
public static IEnumerable Scan() {
Ping p = new Ping();
List activeIPs = new List();
for (int i = 0; i < byte.MaxValue; i++) {
PingReply pr = p.Send(IPAddress.Parse("192.168.1." + i));
activeIPs.Add(pr?.Address.ToString());
}
return activeIPs;
}
}

Causes a BSOD with PROCESS_HAS_LOCKED_PAGES error when terminating the process before the method finished executing.
After googling around it seems MS has had this issue for a while (at least since NT days) and have not fixed it.

Example above is synchronous to test in a more basic case (which still caused the crash)

Any workarounds my dudes?

Install Gentoo

Inst󠀸all Gen󠀸to󠀸o󠀸

public static class NetworkScanner {
public static IEnumerable Scan() {
Ping p = new Ping();
List activeIPs = new List();
for (int i = 0; i < byte.MaxValue; i++) {
PingReply pr = p.Send(IPAddress.Parse("192.168.1." + i));
activeIPs.Add(pr?.Address.ToString());
}
return activeIPs;
}
}

Is this legit? Do you have the bug report? How the hell can that cause a BSOD?

This causes a BSOD even without admin privileges?

I can 100% replicate it in Visual Studio 2015 by closing the program while the method begins execution.

Some stackoverflow people suggested that it has to do with the kernel.

what does the ? do?

equivalent of
if (pr.Address != null)
activeIPs.Add(pr.Address.ToString());

Just tried it, and yep it does, kek

Best solution would probably be to write your own ICMP code with raw sockets, I bet the existing one uses some kernel hack for better speed or some shit written back in 1995

>NT kernel so fucked that sending a simple ping can bring it down

op here
Isn't that fucking hilarious?
I couldn't believe it the first time it happened to me. Thought pc was crapping out.

have you tried to do 1 ping per thread?

If you cancel before the ping ends you crash the code. One hack I had for a bit was to suspend all closing operations until the method was done executing.

Gonna take the advice from above and write custom ICMP

I just ran it and stop it mid way and nothing happened

The windows guy should be c# and macfag is objective-c. The little guy is pythong.

Try changing the IP to match your network, could be failing because your not on 192.168.1.x

I concur. Tried on school network and it instantly finished because the network is not the same type as my home one.

I am tho

dont some home networks run on 10.0.0.x instead of 192.168.1.

nvm, it crashed after trying it 4 times

create set of batch files and run via cmd /c > IP.txt
parse all output files

Never figure out how to wait until the program finishes executing.

you can define wait when you start a process in to run the batch in C#

>meanwhile in OS X
I tested with this on Mono, oddly enough all IPs register as valid... Are you sure this is a bug in .NET and not Windows?
using System;
using System.Net;
using System.Net.NetworkInformation;
using System.Collections.Generic;

public class TestPing{
public static void Main(String[] args){
IEnumerable ips = NetworkScanner.Scan();
foreach (string s in ips){
Console.WriteLine("IP found at : {0}", s);
}
}

}

public static class NetworkScanner {
public static IEnumerable Scan() {
Ping p = new Ping();
List activeIPs = new List();
for (int i = 0; i < byte.MaxValue; i++) {
Console.WriteLine("Pinging 192.168.0." + i);
PingReply pr = p.Send(IPAddress.Parse("192.168.0." + i));
activeIPs.Add(pr?.Address.ToString());
}
return activeIPs;
}
}

Yeah it is exactly what I mean.

As stated above, it is a bug somewhere in the windows kernel that gets called by Ping.Send