Win7 No PingCompletedCallback on timeout?
-
Hey guys, I wrote a network scanning tool a few years ago, which pings a list of IP addresses. I recently moved to Windows 7, and have noticed some strange behaviour in the program. My ping code is as follows:
public void pingIP(int IP)
{
AutoResetEvent waiter = new AutoResetEvent (false);
string IPaddress = IPpart1.Value.ToString() + "." + IPpart2.Value.ToString() + "." + IPpart3.Value.ToString() + "." + IP;
IPAddress IPa = IPAddress.Parse(IPaddress);Debug.WriteLine("Pinging " + IP.ToString()); Ping ping = new Ping(); ping.PingCompleted += new PingCompletedEventHandler(PingCompletedCallback); ping.SendAsync(IPa, waiter); }
This then calls PingCompletedCallback when it recieves a response:
public void PingCompletedCallback(object sender, PingCompletedEventArgs e)
{PingReply reply = e.Reply; // get the IP that was pinged string IP = reply.Address.ToString(); if(IP != "0.0.0.0") { string\[\] IParray = IP.Split('.'); int iIP = Int32.Parse(IParray\[3\]); if (reply.Status == IPStatus.Success) pingResult\[iIP\] = reply.RoundtripTime.ToString(); else pingResult\[iIP\] = "X"; Debug.WriteLine("Ping Reply From " + IP.ToString() + " Time: " + pingResult\[iIP\]); // check if the last ping (255) has been reveived and mark the ping complete flag if so if (iIP == 255) { pingComplete = true; lblStatus.Text = "Ping Complete"; } } ((AutoResetEvent)e.UserState).Set(); }
Now, under Windows XP this worked fine, PingCompletedCallback was called for every ping I sent - either with a response, or with a timeout. I could then set the value as required. However, under Win7, PingCompletedCallback only seems to be called when a successful response is received. I have also noticed I recieve a lot of replies from "0.0.0.0", as well as multiple replies from the IP the machine is running on (10.0.0.4) I have a second screen for doing a detailed ping on a single IP, which doesnt use a call