Aqui não há script bash tão conciso:
#!/bin/bash
v4dec() {
for i; do
echo $i | {
IFS=./
read a b c d e
test -z "$e" && e=32
echo -n "$((a<<24|b<<16|c<<8|d)) $((-1<<(32-e))) "
}
done
}
v4test() {
v4dec $1 $2 | {
read addr1 mask1 addr2 mask2
if (( (addr1&mask2) == (addr2&mask2) && mask1 >= mask2 )); then
echo "$1 is in network $2"
else
echo "$1 is not in network $2"
fi
}
}
v4test 10.1.2.3 10.0.0.0/8
v4test 10.1.2.0/24 10.0.0.0/8
v4test 192.168.0.1 10.0.0.0/8
v4test 10.0.0.0/7 10.0.0.0/8
Saída:
10.1.2.3 is in network 10.0.0.0/8
10.1.2.0/24 is in network 10.0.0.0/8
192.168.0.1 is not in network 10.0.0.0/8
10.0.0.0/7 is not in network 10.0.0.0/8