view scripts/cidr2ip @ 1094:1d2f501fa55e draft

epoch added as 4141 and CIDR 1.41.41.0/24
author epoch <epoch@hacking.allowed.org>
date Sun, 24 Mar 2013 12:51:10 +0000
parents 31e3b4edf502
children
line wrap: on
line source

#!/bin/sh

if [ x"$1" = x ]; then
 echo "Usage: $0 <cidr>" >&2; exit 255
fi

ip="$(echo "$1" | cut -d/ -f1)"
len="$(echo "$1" | cut -d/ -f2)"
if [ x"$((len%8))" != x0 ]; then
 echo "Prefix length must be a multiple of 8" >&2; exit 255
fi
octets="$((len/8))"
for x in `seq 1 $octets` ; do
 echo $ip | cut -d. -f$x
done | tr '\n' . | head -c -1 ; echo