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?
Adrian Williams
Install Gentoo
Gavin Anderson
Install Gentoo
Brandon Perez
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; } }
Colton Lee
Is this legit? Do you have the bug report? How the hell can that cause a BSOD?
Tyler Price
This causes a BSOD even without admin privileges?
Sebastian Martinez
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.
John Jackson
what does the ? do?
Michael Davis
equivalent of if (pr.Address != null) activeIPs.Add(pr.Address.ToString());
Isaac Reed
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
Julian Peterson
op here Isn't that fucking hilarious? I couldn't believe it the first time it happened to me. Thought pc was crapping out.
Jason Ramirez
have you tried to do 1 ping per thread?
Isaiah Murphy
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
Justin Ortiz
I just ran it and stop it mid way and nothing happened
Parker Allen
The windows guy should be c# and macfag is objective-c. The little guy is pythong.
Chase Hernandez
Try changing the IP to match your network, could be failing because your not on 192.168.1.x
Austin Baker
I concur. Tried on school network and it instantly finished because the network is not the same type as my home one.
Isaiah Howard
I am tho
Camden Jenkins
dont some home networks run on 10.0.0.x instead of 192.168.1.
Elijah Peterson
nvm, it crashed after trying it 4 times
Cameron Kelly
create set of batch files and run via cmd /c > IP.txt parse all output files
Jace Nguyen
Never figure out how to wait until the program finishes executing.
Joshua James
you can define wait when you start a process in to run the batch in C#
Owen Jones
>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; } }
Ryder Fisher
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