Bash cript to calculate summarize address

Hi,

I need to write a bash script that when i enter two ip address, it will calculate summerize address for them.

Examlpe:

192.168.1.27/25
192.168.1.129/25

Result will be:

192.168.1.0/24

can you help me with this script?
I even dont know how to start with it

How do you define a "summarize address"? Above addresses are on different subnets, one is 192.168.1.0/25 , and the other is 192.168.1.128/25 . Is the desired result the maximum number of identical leading bits?

Network summarization is the act of taking two or more IP networks and using a single IP network to represent them all

I came up with this - not thoroughly tested, and not necessarily most efficient, and possibly won't run with sh , but seems to work (with e.g. recent bash ):

MAX=0
OLDIP=0
while read LINE
  do    IP=$((0x$(printf "%02X" ${LINE//./ })));
        if [ "$OLDIP" -gt 0 ]
          then  TMP=$((IP ^ OLDIP ))
                if [ "$TMP" -gt "$MAX" ]
                  then MAX=$TMP
                  fi
          fi
        OLDIP=$IP
  done < $1

for ((EXP=1; EXP<=32 && 2**EXP<=MAX; EXP++)); do :; done
NET=$((IP & (2**EXP - 1 ^ 2**32 - 1) ))
printf "SuperNet: %d.%d.%d.%d/%d\n" $((NET>>24)) $((NET>>16&255)) $((NET>>8&255)) $((NET&255)) $((32-EXP));

Put into a script file, make it executable, put your IPs into another file, and run script like

./script filr
SuperNet: 192.168.1.0/24