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. Ping multiple IP adresses

Ping multiple IP adresses

Scheduled Pinned Locked Moved C#
tutorialquestion
6 Posts 3 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.
  • P Offline
    P Offline
    peropata
    wrote on last edited by
    #1

    Hi, What would be the fastest way to ping 255 IP addresses? Are there any example with using multithreading, as I am quite new to threading.

    L 1 Reply Last reply
    0
    • P peropata

      Hi, What would be the fastest way to ping 255 IP addresses? Are there any example with using multithreading, as I am quite new to threading.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      The multi-threading itself isn't problematic; getting it all done in a reasonable time may be a bit of a problem. I would use say four to eight identical instances of a class that starts a thread which, in a loop: - fetches an IP address out of a shared queue; - calls Network.Ping(); - stuffs the result in another shared queue. Of course, both queues need their lock. You should not pre-assign IP addresses to threads, as you can't predict how long a ping operation will take; typically those that succeed run fast, and the failing ones have to wait for their time-out. And adding more threads won't help much as I expect you will end up running in network limitations. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      modified on Wednesday, November 10, 2010 10:49 AM

      P 1 Reply Last reply
      0
      • L Luc Pattyn

        The multi-threading itself isn't problematic; getting it all done in a reasonable time may be a bit of a problem. I would use say four to eight identical instances of a class that starts a thread which, in a loop: - fetches an IP address out of a shared queue; - calls Network.Ping(); - stuffs the result in another shared queue. Of course, both queues need their lock. You should not pre-assign IP addresses to threads, as you can't predict how long a ping operation will take; typically those that succeed run fast, and the failing ones have to wait for their time-out. And adding more threads won't help much as I expect you will end up running in network limitations. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        modified on Wednesday, November 10, 2010 10:49 AM

        P Offline
        P Offline
        peropata
        wrote on last edited by
        #3

        For my application I can set time-out to less then 250ms, so waiting is not a issue. When using lock, does this mean the first thread that access "variable" locks the access and if other threads are trying to access same "variable" wait (like thread.sleep) until it is released?

        L 1 Reply Last reply
        0
        • P peropata

          For my application I can set time-out to less then 250ms, so waiting is not a issue. When using lock, does this mean the first thread that access "variable" locks the access and if other threads are trying to access same "variable" wait (like thread.sleep) until it is released?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          1. 250msec * 255 IP adr / 8 threads is still 8 seconds. 2. yes, said locks would be exclusive, but only while accessing the queue, not while pinging (hence only a small fraction of the time). Like so (in pseudo-code!):

          lock(IPadrLock) {
          IPadr=IPadrQueue.Dequeue();
          }
          result=ping(IPadr);
          lock(resultLock) {
          resultQueue.Enqueue(result);
          }

          :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          P 1 Reply Last reply
          0
          • L Luc Pattyn

            1. 250msec * 255 IP adr / 8 threads is still 8 seconds. 2. yes, said locks would be exclusive, but only while accessing the queue, not while pinging (hence only a small fraction of the time). Like so (in pseudo-code!):

            lock(IPadrLock) {
            IPadr=IPadrQueue.Dequeue();
            }
            result=ping(IPadr);
            lock(resultLock) {
            resultQueue.Enqueue(result);
            }

            :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            P Offline
            P Offline
            peropata
            wrote on last edited by
            #5

            Thank you for your answer. I will also look into "Ping.SendAsync" method, like this one http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/1627b5e9-e18c-441e-aebf-efb2a58d86a7[^]

            M 1 Reply Last reply
            0
            • P peropata

              Thank you for your answer. I will also look into "Ping.SendAsync" method, like this one http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/1627b5e9-e18c-441e-aebf-efb2a58d86a7[^]

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              It is polite to up vote a helpful answer.

              Never underestimate the power of human stupidity RAH

              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