In this tutorial, we will demonstrate you on how to convert IP address ranges into Netmask format. A netmask is a 32-bit number that masks an IP address and divides the IP address into subnets. An example of netmask notation is 22.214.171.124/255.255.255.0. The example represents the IP ranges from 126.96.36.199 to 188.8.131.52. Please pay attention that this tutorial only for the conversion of IPv4 to Netmask format.
This tutorial will not show you a complete project, but the core function of how the conversion work. This function, iprange2netmask, takes 2 input parameters, namely the ipStart and ipEnd, the starting and the ending of an IP address respectively. You can either supply the IP address in dotted format, for example 184.108.40.206, or IP number, for instance, 3401190660, as the input parameters. The function will convert them into IP number if dotted IP address format were supplied and perform the calculation.
Below are the sample codes of the function written in several programming languages, such as PHP, VB.NET, C#, Java and Ruby.
The result that return by the iprange2netmask function is an Array that contain the list of Netmask formatted IP address. Looping have to be done to get all the Netmask formatted IP address from the return result. The following figure shows the sample output with ipStart:192.168.1.0 and ipEnd:192.168.1.9 of the converting IP address ranges into Netmask format.