Fill IP Range

lewinski

Member
Joined
May 28, 2007
Messages
5
Programming Experience
Beginner
I want to fill a list with all valid IPs in a given broadcast address.

Taking the IP and subnet mask from the adapter, I can calculate the subnet ID and broadcast address, i.e.

IP: 192.168.0.1 Subnet Mask: 255.255.255.0

will give me an ID of 192.168.0.0 and a broadcast address of 192.168.0.255.

Therefore I would need fill a list from 192.168.0.1 to 192.168.0.254

(Please note, this is just an example and the address range won't be static, so looping 192.168.0.x 1 to 254 is not what I need).

Ideally, I would like to be able to just send out a ping on the broadcast address and see which IPs respond, but apparently windows does not support broadcast pinging so I first have to enumarate the IPs in the range and ping them in a loop.

I have searched high and low but cannot find the answer. :confused:

Any advice would be appreciated.

Thanking you in advance.
 
See attached project, there is a sample that pings all host in local network asynchronous. It features two classes of mine (in development), IP4Network that gets ip+subnet and calculates the network (using BitArray and bitwise calculations) and Nethood that pings them. The IP4Network class can also be used as a subnet calculator (sample subnetForm included also).
 

Attachments

  • vbnet20-nethood.zip
    21 KB · Views: 96
Wow.. all I asked for was an enumaration of a range once the first and last addresses were known.. but youve practically finished the entire project for me!

Your network ping works so much faster than the way I had it, so thats a bonus too..

:D

Many, many thanks. This is far better than I hoped for.
 
Just two development projects I had lying around, it only took a minute combining them and uploading. Glad it helped. The Nethood class has Ping set for 10ms timeout and 1 hop TTL (TimeToLive, with PingOptions constructor), it should work in most local networks (with only 1ms timeout too actually).
 
Back
Top