Mercurial > hg > anonet-resdb
annotate scripts/cidr2ip @ 764:b7e62d7be4df draft
Merge commit '878cb53c4f76135dffe74ad1452a541ead04f9b3'
author | Nick <nick@somerandomnick.ano> |
---|---|
date | Tue, 15 Nov 2011 19:33:12 +0000 |
parents | 31e3b4edf502 |
children |
rev | line source |
---|---|
19
31e3b4edf502
scripts for dom&ip, dn42 resdb, and doc (www.anonet2.org)
Nick <nick@somerandomnick.ano>
parents:
diff
changeset
|
1 #!/bin/sh |
31e3b4edf502
scripts for dom&ip, dn42 resdb, and doc (www.anonet2.org)
Nick <nick@somerandomnick.ano>
parents:
diff
changeset
|
2 |
31e3b4edf502
scripts for dom&ip, dn42 resdb, and doc (www.anonet2.org)
Nick <nick@somerandomnick.ano>
parents:
diff
changeset
|
3 if [ x"$1" = x ]; then |
31e3b4edf502
scripts for dom&ip, dn42 resdb, and doc (www.anonet2.org)
Nick <nick@somerandomnick.ano>
parents:
diff
changeset
|
4 echo "Usage: $0 <cidr>" >&2; exit 255 |
31e3b4edf502
scripts for dom&ip, dn42 resdb, and doc (www.anonet2.org)
Nick <nick@somerandomnick.ano>
parents:
diff
changeset
|
5 fi |
31e3b4edf502
scripts for dom&ip, dn42 resdb, and doc (www.anonet2.org)
Nick <nick@somerandomnick.ano>
parents:
diff
changeset
|
6 |
31e3b4edf502
scripts for dom&ip, dn42 resdb, and doc (www.anonet2.org)
Nick <nick@somerandomnick.ano>
parents:
diff
changeset
|
7 ip="$(echo "$1" | cut -d/ -f1)" |
31e3b4edf502
scripts for dom&ip, dn42 resdb, and doc (www.anonet2.org)
Nick <nick@somerandomnick.ano>
parents:
diff
changeset
|
8 len="$(echo "$1" | cut -d/ -f2)" |
31e3b4edf502
scripts for dom&ip, dn42 resdb, and doc (www.anonet2.org)
Nick <nick@somerandomnick.ano>
parents:
diff
changeset
|
9 if [ x"$((len%8))" != x0 ]; then |
31e3b4edf502
scripts for dom&ip, dn42 resdb, and doc (www.anonet2.org)
Nick <nick@somerandomnick.ano>
parents:
diff
changeset
|
10 echo "Prefix length must be a multiple of 8" >&2; exit 255 |
31e3b4edf502
scripts for dom&ip, dn42 resdb, and doc (www.anonet2.org)
Nick <nick@somerandomnick.ano>
parents:
diff
changeset
|
11 fi |
31e3b4edf502
scripts for dom&ip, dn42 resdb, and doc (www.anonet2.org)
Nick <nick@somerandomnick.ano>
parents:
diff
changeset
|
12 octets="$((len/8))" |
31e3b4edf502
scripts for dom&ip, dn42 resdb, and doc (www.anonet2.org)
Nick <nick@somerandomnick.ano>
parents:
diff
changeset
|
13 for x in `seq 1 $octets` ; do |
31e3b4edf502
scripts for dom&ip, dn42 resdb, and doc (www.anonet2.org)
Nick <nick@somerandomnick.ano>
parents:
diff
changeset
|
14 echo $ip | cut -d. -f$x |
31e3b4edf502
scripts for dom&ip, dn42 resdb, and doc (www.anonet2.org)
Nick <nick@somerandomnick.ano>
parents:
diff
changeset
|
15 done | tr '\n' . | head -c -1 ; echo |