Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Win7 No PingCompletedCallback on timeout?

Win7 No PingCompletedCallback on timeout?

Scheduled Pinned Locked Moved C#
sysadmindebuggingquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gavin Coates
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups