• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 792
  • Last Modified:

Span Multiple Threads to Ping List of IPs

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)
next"


Thank you.
0
APag96
Asked:
APag96
  • 4
  • 2
1 Solution
 
ullfindsmitCommented:
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

Next

Open in new window

0
 
APag96Author Commented:
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?

Thanks
0
 
APag96Author Commented:
I understand your code now. But I need to be able to specify how many threads will be used to ping an IP.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
ullfindsmitCommented:
you can use a counter and increment it in the loop and decrement it in the event handler
0
 
APag96Author Commented:
Event handlers are new to me. Could you please provide an example?
0
 
APag96Author Commented:
I have solved my own problem. Here is the link to the code I found: http://www.pberblog.com/post/2009/07/21/Multithreaded-ping-sweeping-in-VBnet.aspx

The code is ABSOLUTELY amazing!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now