Announcement

Collapse
No announcement yet.

Create IP Address Range using Windows Command Prompt

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create IP Address Range using Windows Command Prompt

    There are times when we need to create a text file that contains the IP address range of the network that we are going to scan or test. Creating this text file manually is a tedious task. However, windows scriptingis there for our help.

    To create a text file containing the IP addresses in the range 192.168.1.1 to 192.168.1.254, you can enter the following command at the command prompt:
    for /l %%i in (1,1,254) do echo 192.168.1.%%i >> iplist.txt

    Let's understand the above command:

    Part 1 - for /l %%i in (1,1,254)

    Here, we are using the FOR command to create a looping construct. With the /l switch for the FOR command, we can execute a command a given number of times based on the parameters. In this case, the parameters are (1,1,254), where the first parameter (1) denotes the starting value, the second paramter (1) denotes the step or number to increment, and the third parameter (254) denotes the end value.

    The above command will loop through the value starting at 1, adding 1 to each value and finally stoping at 254.

    %%i is the variable assigned that will hold the current value.



    Part 2 - do echo 192.168.1.%%1

    For each loop instance, the hard coded Network ID - 192.168.1 along with the value of the variable i will be displayed to the standard output. In this case, the value will be displayed in the screen.



    Part 3 - >> iplist.txt

    We are redirecting the output of the program to a file named iplist.txt. We are using the redirector >> to pass the value to the file.
Working...
X