Skip to content

Instantly share code, notes, and snippets.

@boina-n
Created October 22, 2017 15:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boina-n/432452bab82c6a46e70f4c98bb8de7e8 to your computer and use it in GitHub Desktop.
Save boina-n/432452bab82c6a46e70f4c98bb8de7e8 to your computer and use it in GitHub Desktop.
Convert Infoblox zones to Bind Zones
#!/bin/bash
echo "#############################################################"
echo "#############################################################"
echo "## Infoblox to bind export script ##"
echo "## This script should be run on ##"
echo "## a server allowed transfer the zones ##"
echo "## the zones by transfer ##"
echo "#############################################################"
echo "#############################################################"
workingdir=`pwd`
zone_file=Allzones_infoblox_10072010.csv
master_ip=x.x.x.x
mkdir -p $workingdir/master/fwrd $workingdir/master/rev
sed 's/^"\|"$//g' < $zone_file | sed 's/""/"/g' | grep '^delegatedzone\|^header-delegatedzone' > $workingdir/master/$zone_file.delegated.csv
sed 's/^"\|"$//g' < $zone_file | sed 's/""/"/g' | grep '^authzone\|^header-authzone' > $workingdir/master/$zone_file.authzone.csv
# Transfère des zones forward autoritaire.
awk -F ',' '$3 ~ /FORWARD/ { print $2 }' $workingdir/master/$zone_file.authzone.csv | while read p
do dig @$master_ip $p axfr > $workingdir/master/fwrd/db.$p
sleep .1
done
# Generation du fichier autozone pour les zones forward autoritaire
awk -F ',' '$3 ~ /FORWARD/ { print $2 }' $workingdir/master/$zone_file.authzone.csv | while read p
do echo -e "zone $p IN { \\n\\ttype master; \\n \\tfile \"$workingdir/master/fwrd/db.$p\";\\n}; \\n" >> $workingdir/master/autozones.conf
done
# Transfère des zones reverse autoritaire.
awk -F ',' '$3 ~ /IPV4/ { print $2 }' $workingdir/master/$zone_file.authzone.csv | while read p
do dig @$master_ip $(echo $p | awk -F. '{print $3"."$2"."$1}').in-addr.arpa axfr > $workingdir/master/rev/db.$(echo $p | awk -F. '{print $3"."$2"."$1}').in-addr.arpa
sleep .1
done
# Generation du fichier rev pour les zones rev autoritaire
awk -F ',' '$3 ~ /IPV4/ { print $2 }' $workingdir/master/$zone_file.authzone.csv | while read p
do echo -e "zone $(echo $p | awk -F. '{print $3"."$2"."$1}').in-addr.arpa. IN { \\n\\ttype master; \\n \\tfile \"$workingdir/master/rev/db.$(echo $p | awk -F. '{print $3"."$2"."$1}').in-addr.arpa\";\\n}; \\n" >> rev.conf
done
#######################
#
# DELEGATED ZONES
#
#######################
awk -F ',' '$4 ~ /FORWARD/ { print $3 }' $workingdir/master/$zone_file.delegated.csv | while read p
do dig @$master_ip $p axfr > $workingdir/master/fwrd/db.$p
sleep .1
done
awk -F ',' '$4 ~ /FORWARD/ { print $3 }' $workingdir/master/$zone_file.delegated.csv | while read p
do echo -e "zone $p IN { \\n\\ttype master; \\n \\tfile \"$workingdir/master/fwrd/db.$p\";\\n}; \\n" >> autozones.conf
done
awk -F ',' '$4 ~ /IPV4/ { print $3 }' $workingdir/master/$zone_file.delegated.csv | while read p
do dig @$master_ip $(echo $p | awk -F. '{print $3"."$2"."$1}').in-addr.arpa axfr > $workingdir/master/rev/db.$(echo $p | awk -F. '{print $3"."$2"."$1}').in-addr.arpa
sleep .1
done
awk -F ',' '$4 ~ /IPV4/ { print $3 }' $workingdir/master/$zone_file.delegated.csv | while read p
do echo -e "zone $(echo $p | awk -F. '{print $3"."$2"."$1}').in-addr.arpa. IN { \\n\\ttype master; \\n \\tfile \"$workingdir/master/rev/db.$(echo $p | awk -F. '{print $3"."$2"."$1}').in-addr.arpa\";\\n}; \\n" >> rev.conf
done
## SLAVE ::
# autozones.slave.conf generation:
awk -F ',' '$3 ~ /IPV4/ { print $2 }' $workingdir/master/$zone_file.authzone.csv | while read p ; do echo -e "zone $p IN { \\n\\ttype slave;\\n\\tmasters {10.90.22.145;};\\n\\tfile \"slave/fwrd/db.$p\";\\n};\\n" >> rev.slave.conf ; done
awk -F ',' '$3 ~ /FORWARD/ { print $2 }' $workingdir/master/$zone_file.authzone.csv | while read p
do echo -e "zone $p IN { \\n\\ttype slave;\\n\\tmasters {10.10.10.10;};\\n\\tfile \"slave/fwrd/db.$p\";\\n};\\n" >> autozones.slave.conf
done
## Partie Test
#Resperf Tests :
awk -F ',' '$3 ~ /FORWARD/ { print $2" SOA" }' $workingdir/master/$zone_file.authzone.csv | dnsperf -v -s $host -Q 100 | grep -v '> NOERROR'
awk -F ',' '$3 ~ /IPV4/ { print $2}' $workingdir/master/$zone_file.authzone.csv | awk -F. '{print $3"."$2"."$1".in-addr.arpa SOA"}' | dnsperf -v -s $host -Q 100 | grep -v '> NOERROR'
awk -F ',' '$4 ~ /FORWARD/ { print $3" SOA" }' $workingdir/master/$zone_file.delegated.csv | dnsperf -v -s $host -Q 100 | grep -v '> NOERROR'
awk -F ',' '$4 ~ /IPV4/ { print $3}' $workingdir/master/$zone_file.delegated.csv | awk -F. '{print $3"."$2"."$1".in-addr.arpa SOA"}' | dnsperf -v -s $host -Q 100 | grep -v '> NOERROR'
# vérifie la fiabilité des domaines sur le primaire du tld sn.
awk -F ',' '$3 ~ /FORWARD/ { print $2 }' $workingdir/master/$zone_file.authzone.csv | head -n 10 | while read p ; do echo -n $p ';' $(dig @8.8.8.8 $p NS +short while read p ; do for i in $p ; do echo -n $i';' ; done ; done) ; done
echo -n ';'
sleep .1
done
# Test delegated and auth zones with resperf with a google DNS.
awk -F ',' '$4 ~ /FORWARD/ { print $3" A" }' $workingdir/master/$zone_file.delegated.csv | dnsperf -v -s $host -Q 100
# check NS of all FQND:
awk -F ',' '$4 ~ /FORWARD/ { print $3 }' $workingdir/master/$zone_file.delegated.csv | head -n 10 | while read p
do echo 'dig @$master_ip $p axfr'
dig @$master_ip $p axfr
sleep .1
done
awk -F ',' '$3 ~ /FORWARD/ { print $2 }' $workingdir/master/$zone_file.authzone.csv | head -n 10 | while read p ; do echo -n $p ';' $(dig @8.8.8.8 $p NS +short while read p ; do for i in $p ; do echo -n $i';' ; done ; done) ; done
echo -n ';'
sleep .1
done
echo -e "zone $p IN { \\n\\ttype slave;\\n"masters \\n\\tfile \"$workingdir/master/fwrd/db.$p\";\\n}; \\n"
cat authzone.forward.txt | while read p
do echo -e "zone $p IN { \\n\\ttype master;\\n\\talso-notify {10.10.10.10;10.10.12.10;};\\n\tallow-transfer {10.10.10.10;10.10.12.10;};\\n\\tfile \"$workingdir/master/fwrd/db.$p\";\\n};\\n" >> autozones.conf
done
cat authzone.forward.txt | while read p
do echo -e "zone $p IN { \\n\\ttype slave;\\n\\tmasters {10.10.10.10;10.10.12.10;};\\n\\tfile \"slave/fwrd/db.$p\";\\n};\\n" >> autozones.slave.conf
done
cat authzone.ipv4.txt | while read p
do echo -e "zone $(echo $p | awk -F. '{print $3"."$2"."$1}').in-addr.arpa. IN { \\n\\ttype slave;\\n\\tmasters {10.10.10.10;10.10.12.10;};\\n\\tfile \"slave/rev/db.$(echo $p | awk -F. '{print $3"."$2"."$1}').in-addr.arpa\";\\n}; \\n" >> rev.conf
done
@silviomacias
Copy link

is this portion of code supposed to be run in the actual Infoblox authoritative servers? thanks...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment