Span Multiple Threads to Ping List of IPs

Posted on 2009-12-22
Last Modified: 2012-05-08
Have you ever seen those IP scanner programs where it goes through a range of IP addresses and pings each on on a separate thread and then returns the result?

I am making my OWN version of that. I have got everything done so far except that the pinging is VERY slow. In the commercial version of these programs, you can ask it to use 50 threads (just an example number) for pinging an IP on each. Of course, using 50 threads compared to 1 is MUCH faster.

But how do I spawn 50 different threads and ping a different IP address on each. I would also like the user to be able to input how many threads he wants the program to use.

I am using the Visual Studio code snippet ping code (My.Computer.Network.Ping(ip)) to ping the IPs.

THIS DOES NOT WORK: (Just letting you know.)
"for i = 1 to 50
 dim s as new system.threading.thread(AddressOf pinger)

Thank you.
Question by:APag96
    LVL 12

    Expert Comment

    Below is some code to help you get started.
    'YOUR MyPinger.VB class
    Public Class MyPinger
    Public myIp2Ping as String
    Public Event PingComplete(IP_Pinged as String)
    Public Function DoPing() as String
    'Logic goes here
    raiseevent PingComplete(myIp2Ping)
    End Function
    End Class
    'Your Normal.VB Class
    For Each dr as DataRow in dt.Rows
     Dim p as New MyPinger
     p.myIp2Ping = dr("IP2Ping")
     Dim t as new Thread( AddressOf p.DoPing )
     AddHandler p.PingComplete, ThisClassShouldHaveAHandlerIHaventBuiltHere

    Open in new window


    Author Comment

    I'm very sorry, I do not completely understand your code. VS found many error. I am unable to correct all of them. Do you have more "complete" code?


    Author Comment

    I understand your code now. But I need to be able to specify how many threads will be used to ping an IP.
    LVL 12

    Expert Comment

    you can use a counter and increment it in the loop and decrement it in the event handler

    Author Comment

    Event handlers are new to me. Could you please provide an example?

    Accepted Solution

    I have solved my own problem. Here is the link to the code I found:

    The code is ABSOLUTELY amazing!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Javascript: Crash Course

    Javascript is not only emerging as the most important language to know, it's flexibility is unique. With Javascript being deployed on the web, mobile and even the desktop this is the one language that all technologists need to know.

    Suggested Solutions

    Title # Comments Views Activity
    Help needed on website authentication 7 37
    python question 5 37
    to transfer string from C lanaguage to VBA 4 36
    Xamarin 10 18
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now