Range of Host IPs in the network

I am able to get the IP address and Subnet Mask programatically. Is there a way we could generate all addressable host IPs with these two information?

I am just trying to develop a simple Ping Sweep module for my application.

Thanks.

PS: I am using C# .NET 3.5.

Answers


Calculate the first and last host IP addresses and then iterate over them sequentially. The first IP address is (address & mask) + 1. The last is (address | ~mask) - 1.

So if the network is 192.168.132.0 and the netmask is 255.255.255.0, the first eligible host IP is:

(address & mask) + 1
(192.168.132.0 & 255.255.255.0) + 1
192.168.132.0 + 1
192.168.132.1

The last eligible host IP is:

(address | ~mask) - 1
(192.168.132.0 | ~(255.255.255.0)) - 1
(192.168.1.32.0 | (0.0.0.255)) - 1
192.168.132.255 - 1
192.168.132.254

So the valid host addresses are 192.168.132.1 through 192.168.132.254 inclusive.


Need Your Help

Calibri font printed as Arial

reporting-services printing fonts ssrs-2008

I have a Report that uses the Calibri font. It is rendered fine in IE, however when I print the report (clicking on the Printer icon) the text comes out in Arial.

Esablishing if file exists on another domain using javascript

javascript html html5 http

I wish to test from javascript within my html page if the following files exist or not:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.