ksh - how to list all ip address between 2 ip address

Trying to do a ksh script that needs to list all ip address between ip address a and b ..

ie.
Ip address A=192.168.1.200
Ip address B=192.168.2.15

So the subnet changes from 1 to 2 but I want to list all possible ip addresses between the 2..

Which would be:
192.168.1.200
192.168.1.201..... up to .254
192.168.2.1
192.168.2.2.... up to .15

The script need to be able to cater for different subnets etc..

Any help?

just use 2 for loops

awk 'BEGIN{
 for(i=1;i<=2;i++){
  for(j=1;j<=254;j++){
   print "192.168."i"."j
  }
 }
} ' 

Thanks.. I copy /pasted this in to script on its own and ran and it works fine - but it doesnt seem to complete... it doesnt return to command line unless I CTRL-C

Do you know why this is? is there something missing to end the for loop?

-----Post Update-----

Actually - this doesnt appear to work as I had hoped.
ie. If my start ip was 192.168.1.1 and end was 192.168.2.4 then in the script above i <=1 and j<=4 so I only get the following listed

192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4
192.168.2.1
192.168.2.2
192.168.2.3
192.168.2.4

So everything before 192.168.1.4 and 192.168.2.1 is missing....

-----Post Update-----

I figured out how I can do this in a ksh script - a bit long winded and I am sure there is easier way to do it but it works..

Run script with start ip address as arugment 1 and end ip address as argument 2

./getrange.sh 192.168.1.1 192.168.3.50

getrange.sh

#!/usr/bin/ksh
#set -x

a1=$1
b1=$2

a1subnet=`echo $a1 | cut -d. -f3`
a1ipadd=`echo $a1 | cut -d. -f4`
b1subnet=`echo $b1 | cut -d. -f3`
b1ipadd=`echo $b1 | cut -d. -f4`

if [ $b1subnet -gt $a1subnet ]
then

## A1 list
a1ipaddnumb=$a1ipadd
while [ $a1ipaddnumb -le 254 ]
do
echo "194.20.$a1subnet.$a1ipaddnumb"
a1ipaddnumb=$(($a1ipaddnumb+1))
done

## Any list between A1 and B1
xsubnet=$(($a1subnet+1))

if [ $xsubnet -lt $b1subnet ]
then
while [ $xsubnet -lt $b1subnet ]
do
xipaddnumb=1
while [ $xipaddnumb -le 254 ]
do
echo "194.20.$xsubnet.$xipaddnumb"
xipaddnumb=$(($xipaddnumb+1))
done
xsubnet=$(($xsubnet+1))
done
fi

## B1 list
b1ipaddnumb=1
while [ $b1ipaddnumb -le $b1ipadd ]
do
echo "194.20.$b1subnet.$b1ipaddnumb"
b1ipaddnumb=$(($b1ipaddnumb+1))
done

fi

specific to ur example

 
 awk -F"." '{ if(NR==1){ for(i=$4;i<=254;i++) print $1"."$2"."$3"."i >> "file_op" } else { for(i=1;i<=$4;i++) print $1"."$2"."$3"."i >> "file_op" }} ' input_file.txt

If you are using ksh93 you can use the ?: construct to more easily handle the start and end conditions.

#!/usr/bin/ksh93

START="192.168.7.245"
STOP="192.168.8.5"

integer i j

IFS="." typeset -a aStart=($START)
IFS="." typeset -a aStop=($STOP)

for (( i=${aStart[2]}; i <= ${aStop[2]}; i++ ))
do
    start=$(( i == ${aStart[2]} ? ${aStart[3]} : 0 ))
    stop=$(( i == ${aStop[2]} ? ${aStop[3]} : 254 ))

    for (( j=$start; j <= $stop; j++ ))
    do
       printf "192.168.%d.%d\n" $i $j
    done
done

gives

192.168.7.245
192.168.7.246
192.168.7.247
192.168.7.248
192.168.7.249
192.168.7.250
192.168.7.251
192.168.7.252
192.168.7.253
192.168.7.254
192.168.8.0
192.168.8.1
192.168.8.2
192.168.8.3
192.168.8.4
192.168.8.5