rand_ip.sh is a simple bash script to generate random IP addresses with a random CIDR subnet mask. The CIDR mask is in the range of 15-30. This can generate a large number of random IP addresses to use with subnet exercises. The following picture is a sample output:

Currently the IP addresses generated will be picked from all classes and both public and private ranges. I am looking to add additional features to the script including the ability to pick which class to use. In the mean time the following is the source code if anyone wishes to try it:

# Random IP and CIDR subnet mask generator
# v1.1 07/28/19 am401

usage () {
echo "rand_ip [-h | --help] [-n | --number #]"

case $1 in
           -n | --number )
                for i in $(eval echo {1..$2}); do
                  ip=$(printf "%d.%d.%d.%d" "$((RANDOM % 256))" \
                     "$((RANDOM % 256))" "$((RANDOM % 256))" \
                     "$((RANDOM % 256))")
                  echo $ip"/"$subnetmask
            -h | --help ) usage
             * ) usage

Leave a Reply

Your email address will not be published. Required fields are marked *