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?
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