0

I want to write a bash script in order to get two IP addresses and shows me whole range between them...

I'm trying but unfortunately no result...

Could you possibly help me?

I found this one but not complete:

addresses=( `< listofnums` )
network=${addresses[0]%.*}
hosts=( ${addresses[@]##*.} )

for (( i=${hosts[0]}; i<255; ++i ))
do
        case "${hosts[@]}" in *"$i"*) ;; *) echo "$network.$i" ;; esac
done

This script would get for example 1.1.1.1 5.4.6.3 and cat me whole range between them.

Thibault
  • 1,566
  • 15
  • 22
MLSC
  • 5,872
  • 8
  • 55
  • 89

1 Answers1

1

Use the functions in this answer: https://stackoverflow.com/a/3222521/116957

And then this should give you what you want:

read -p "IP1> " ip1
read -p "IP2> " ip2

ip1n=$(INET_ATON $ip1)
ip2n=$(INET_ATON $ip2)

if [[ $ip2n -lt $ip1n ]]; then
    echo "Wrong range: $ip1 - $ip2"
    exit 1;
fi

for ipn in $(seq $ip1n $ip2n)
do
    INET_NTOA $ipn
done
Community
  • 1
  • 1
Jacobo de Vera
  • 1,863
  • 1
  • 16
  • 20