Hello
I am trying to generate a script to run on worldwide firewalls.
I need the spf block for large sites like google, etc so I can essentially whitelist google sites for users.
(Google here is just an example...)
Right now I am just testing Bash oneliners to see how I can isolate the data I need.
I want a list of networks with CIDR - this I can feed directly into my whitelist.
My script:
#!/bin/bash
site=${1} # not necc - just like to have a variable for this
diglist=`dig txt ${site} | grep v=spf1 | cut -d : -f2 | cut -d " " -f1`
arr01=( `dig txt $diglist | grep v=spf1 | cut -d \" -f2 | sed s/ip4://g` )
for i in $(seq 1 $((${#arr01
[*]} - 2)))
do
echo ${arr01[${i}]}
done
I am happy to say it more or less works for my purposes.
But it is not very good.
I see the recursion there with the dig statements and know there must be a better way. Lots of kludgy cut statements - I should be able to just capture the IP blocks and load them into an array.
With I knew Perl/Python a little better or even awk (keeping in a Bash frame of mind).
How could I fix this?
yrs
Michael