Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jasan/normalize test #46

Merged
merged 5 commits into from
Dec 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ UDP packet, splitting into more TXT records if needed.

One TXT record per line of standard output.

./despf.sh | ./simplify.sh | ./mkblocks.sh
./despf.sh | ./normalize.sh | ./simplify.sh | ./mkblocks.sh


### compare.sh
Expand All @@ -94,6 +94,23 @@ In order to semi-automate the task of updating the records,
pipe the output of `mkblocks.sh` to `xsel.sh`.


### normalize.sh

This script takes care of correct CIDR ranges. At the moment
only IPv4.

Example:

$ ./normalize.sh <<EOF
> ip4:207.68.169.173/30
> ip4:207.68.169.175/30
> ip4:65.55.238.129/26
> EOF
ip4:207.68.169.172/30
ip4:207.68.169.172/30
ip4:65.55.238.128/26


### simplify.sh

This script takes out individual IPv4 addresses which are already
Expand Down Expand Up @@ -126,13 +143,16 @@ without modifying the script.

Usage:

./despf.sh | ./simplify.sh | ./mkblocks.sh | \
./mkzoneent.sh | ./cloudflare.sh
./despf.sh | ./normalize.sh | ./simplify.sh | ./mkblocks.sh \
> /tmp/out 2>&1
grep "Too many DNS lookups!" /tmp/out \
|| cat /tmp/out | ./mkzoneent.sh | ./cloudflare.sh


## Example

./despf.sh | ./simplify.sh | ./mkblocks.sh | ./xsel.sh
./despf.sh | ./normalize.sh | ./simplify.sh \
| ./mkblocks.sh | ./xsel.sh


## Links
Expand Down
22 changes: 11 additions & 11 deletions normalize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,31 @@ int2ip() {
}

network() {
local ip netmask
echo $1 | while IFS="/" read ip netmask; do
local addr=$(ip2int $ip);
local ia netmask
echo $1 | while IFS="/" read ia netmask; do
local addr=$(ip2int $ia);
local mask=$((0xffffffff << (32 -$netmask)));
echo $(int2ip $((addr & mask)))/$netmask
done
}

while
read ip
read i
do
cidr=$(echo $ip | cut -d: -f2)
ipver=$(echo $ip | cut -d: -f1)
cidr=$(echo $i | cut -d: -f2)
ipver=$(echo $i | cut -d: -f1)
if [ $ipver = "ip4" ] ; then
# check if is a CIDR
cidr=$(echo $ip | cut -d: -f2 -)
nm=$(echo $ip | cut -s -d/ -f2)
cidr=$(echo $i | cut -d: -f2 -)
nm=$(echo $i | cut -s -d/ -f2)
if [ "x$nm" = "x32" ] ; then
echo $ip
echo $i
elif [ "x$nm" = "x" ] ; then
echo $ip
echo $i
else
echo "ip4:$(network $cidr)"
fi
else
echo $ip
echo $i
fi
done
2 changes: 1 addition & 1 deletion runspftools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exec > $HOME/runspftools.log 2>&1
date
git pull
compare.sh $DOMAIN $ORIG_SPF || despf.sh $ORIG_SPF \
| simplify.sh | mkblocks.sh $DOMAIN \
| normalize.sh | simplify.sh | mkblocks.sh $DOMAIN \
| mkzoneent.sh | cloudflare.sh $DOMAIN
sleep 300
exec $0
Expand Down
1 change: 1 addition & 0 deletions tests/normalize/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$(which normalize.sh)
3 changes: 3 additions & 0 deletions tests/normalize/in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ip4:207.68.169.173/30
ip4:207.68.169.175/30
ip4:65.55.238.129/26
3 changes: 3 additions & 0 deletions tests/normalize/out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ip4:207.68.169.172/30
ip4:207.68.169.172/30
ip4:65.55.238.128/26