Shellscript for BND IPs

IP address ranges have been leaked to wikileaks. I wrote a quick ‘n dirty shell script to parse my webserver access log files for these IP ranges.

#!/bin/bash

CountIpRanges ()
{
(cat <<EOF
193.159.228.32 - 193.159.228.39
193.159.238.168 - 193.159.238.175
194.25.184.16 - 194.25.184.23
194.25.42.232 - 194.25.42.239
195.145.128.56 - 195.145.128.63
195.145.163.64 - 195.145.163.127
195.145.182.96 - 195.145.182.111
195.145.31.252 - 195.145.31.255
195.145.57.176 - 195.145.57.191
195.243.157.184 - 195.243.157.191
195.243.248.224 - 195.243.248.231
212.185.184.224 - 212.185.184.231
212.185.191.128 - 212.185.191.135
217.7.155.168 - 217.7.155.175
217.89.74.208 - 217.89.74.223
62.153.59.192 - 62.153.59.223
62.153.65.32 - 62.153.65.39
62.153.80.208 - 62.153.80.215
62.153.87.0 - 62.153.87.15
62.154.211.152 - 62.154.211.159
62.154.226.64 - 62.154.226.127
62.156.187.232 - 62.156.187.239
62.157.136.64 - 62.157.136.95
62.157.144.0 - 62.157.144.63
62.157.193.128 - 62.157.193.223
62.157.194.32 - 62.157.194.39
62.159.19.208 - 62.159.19.215
62.159.104.160 - 62.159.104.175
62.159.209.144 - 62.159.209.151
62.159.209.152 - 62.159.209.159
62.159.21.152 - 62.159.21.159
62.159.60.144 - 62.159.60.151
62.159.63.72 - 62.159.63.79
62.225.139.248 - 62.225.139.255
62.225.74.128 - 62.225.74.135
80.146.198.88 - 80.146.198.95
62.159.104.160 - 62.159.104.175
EOF
) | sed 's/ //g' | awk -F- '{ split($1,IPS,".") ;  split($2,IPE,".") ; \
for (I=IPS[4];I&lt;IPE[4];I++) { print IPS[1]"."IPS[2]"."IPS[3]"."I } }'
}

CountIpRanges | grep -H -f - $1