Difference between revisions of "Get-root-zone"

From CDOT Wiki
Jump to: navigation, search
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:OPS535]][[Category:rchan]]
 
[[Category:OPS535]][[Category:rchan]]
 +
= Bash Script=
 +
Sample Bash script for extracting Domain Registration wiki page [[Domainreg]] and create a root zone file.
 +
Set the following shell (environment) variables before running the script to produce a customized zone file header for that root zone that match your DNS server:
 +
* RNS_FQDN - set this to the fully qualified domain name of your root name server.
 +
** <pre> export RNS_FQDN=rns.cp.net</pre>
 +
* RNS_IP - set this to the IP address of your root name server.
 +
* DNS_ADMIN_EMAIL - set this to the email address of your DNS administrator
 +
** <pre> export DNS_ADMIN_EMAIL=admin.cp.net</pre>
  
Bash script for extracting Domain Registration page and create a root zone file.
+
<pre>
 +
#!/bin/bash
 +
# Created by: Raymond Chan
 +
# for OPS535
 +
# (c) 2016 - update for new wiki site
 +
# (c) 2017 - update to prompt user to set the followings
 +
#     fqdn,ip for root name server
 +
#     email for dns admin
 +
# RNS_FQDN, RNS_IP, DNS_ADMIN_EMAIL
 +
# (c) 2020 - update for the new wiki url
 +
#
 +
if [ -z "${RNS_FQDN}" ]
 +
then
 +
echo "Please set the shell variable RNS_FQDN to the FQDN of your" >&2
 +
echo "root name server and run this script again." >&2
 +
exit 1
 +
fi
  
<pre>
+
if [ -z "${RNS_IP}" ]
#!/bin/bash
+
then
# Created by: Raymond Chan
+
echo "Please set the shell variable RNS_IP to the IP address" >&2
# for OPS535
+
        echo "of your root name server and run this script again." >&2
# (c) 2010
+
exit 2
url=http://zenit.senecac.on.ca/wiki/index.php/Domainreg
+
fi
+
 
if [ ! -f raw.txt ]
+
if [ -z "${DNS_ADMIN_EMAIL}" ]
then
+
then
    echo "Gettting wiki file from the web ..." >&2
+
echo "Please set the shell variable DNS_ADMIN_EMAIL to the" >&2
    wget -O raw.txt $url
+
echo "email address of your DNS administrator and run this" >&2
fi
+
        echo "script again." >&2
+
exit 3
buffer=$(cat raw.txt| grep ^'</td><td>')
+
fi
+
# start loading dns information from the web
nl=$(echo "$buffer"|wc -l)
+
url=https://wiki.cdot.senecacollege.ca/w/index.php/Domainreg
a=0
+
 
b=5
+
if [ ! -f raw.txt ]
+
then
while [ $a -lt $nl ]
+
echo "Gettting wiki file from the web ..." >&2
do
+
wget -O raw.txt $url
    stuff=$(echo "$buffer"| head -"$b" | tail -5|nl|sed -e "s/<\/td><td>/x/g")
+
fi
    #  echo "$stuff"
 
    fields=$(echo "$stuff"|sed -e "s/ //g"|awk -Fx {'print $2'})
 
  
    parameters=$(echo $fields)
+
buffer=$(cat raw.txt| grep ^'<td>')
    paratest=$(echo $parameters | sed -e "s/ //g")
 
    cc=$(echo $paratest | wc -w)
 
        # echo "paratest cc is $cc"
 
  
    if [ $cc -gt 0 ]
+
nl=$(echo "$buffer"|wc -l)
    then   
+
a=0
        #echo $a $parameters
+
b=6
        #read yyy   
+
# generating the zone file header
        set $parameters
+
SN=$(date +%y%j%H) # yydddHH
 +
echo "\$TTL 3600"
 +
echo "@ IN SOA ${RNS_FQDN} ${DNS_ADMIN_EMAIL} (${SN} 1h 15m 30d 1h)"
 +
echo "      IN NS ${RNS_FQDN}"
 +
echo "${RNS_FQDN} IN A ${RNS_IP}"
  
        if [ "$1" != "" -a "$3" != "" -a "$4" != "" ]
+
while [ $a -lt $nl ]
        then
+
do
 +
stuff=$(echo "$buffer"| head -"$b" | tail -5|nl|sed -e "s/<td>/x/g")
 +
#  echo "$stuff"
 +
fields=$(echo "$stuff"|sed -e "s/ //g"|awk -Fx {'print $2'})
  
            echo -e "${1}. \tIN \tNS \t$4."
+
parameters=$(echo $fields)
            echo -e "${4}. \tIN \tA \t$3"
+
cc=$(echo $parameters | wc -w)
            echo " "
+
        # echo "paratest cc is $cc"
  
        fi
+
if [ "$cc" -gt 0 ]
    fi
+
then
 +
#echo $a $parameters
 +
#read yyy
 +
set $parameters
 +
if [ "$1" != "domainname" ]
 +
then
 +
if [ "$1" != "" -a "$3" != "" -a "$4" != "" ]
 +
then
  
    let a=a+5
+
echo -e "${1}. \tIN \tNS \t$4."
    let b=b+5
+
echo -e "${4}. \tIN \tA \t$3"
 +
echo " "
 +
 +
fi
 +
fi
 +
fi
  
    #read xxx
+
let a=a+6
  done
+
let b=b+6
 +
 
 +
#read xxx
 +
done
 +
</pre>
 +
= Sample Output =
 +
<pre>
 +
$TTL 3600
 +
@ IN SOA rns.cp.net. admin.cp.net. (1735109 1h 15m 30d 1h)
 +
      IN NS rns.cp.net.
 +
rns.cp.net. IN A 192.168.99.253
 +
cp.net. IN NS ns.cp.net.
 +
ns.cp.net. IN A 192.168.99.1
 +
 +
Raymond.com. IN NS ns.raymond.com.
 +
ns.raymond.com. IN A 192.168.98.53
 +
   
 +
gcyao.net. IN NS pri-dns.gcyao.net.
 +
pri-dns.gcyao.net. IN A 192.168.33.53
 +
 +
bdgushue.com. IN NS pri-dns.bdgushue.com.
 +
pri-dns.bdgushue.com. IN A 192.168.14.53
 +
 +
dcwood.com. IN NS pri-dns.dcwood.com.
 +
pri-dns.dcwood.com. IN A 192.168.32.53
 +
 +
falli2.com. IN NS pri-dns.falli2.com.
 +
pri-dns.falli2.com. IN A 192.168.2.53
 +
 +
tnemat.com. IN NS a2-dns.tnemat.com.
 +
a2-dns.tnemat.com. IN A 192.168.25.53
 +
 +
accarneirobrandao.net. IN NS pri-dns.accarneirobrandao.net.
 +
pri-dns.accarneirobrandao.net. IN A 192.168.7.53
 
</pre>
 
</pre>

Latest revision as of 06:22, 21 October 2020

Bash Script

Sample Bash script for extracting Domain Registration wiki page Domainreg and create a root zone file. Set the following shell (environment) variables before running the script to produce a customized zone file header for that root zone that match your DNS server:

  • RNS_FQDN - set this to the fully qualified domain name of your root name server.
    •  export RNS_FQDN=rns.cp.net
  • RNS_IP - set this to the IP address of your root name server.
  • DNS_ADMIN_EMAIL - set this to the email address of your DNS administrator
    •  export DNS_ADMIN_EMAIL=admin.cp.net
#!/bin/bash
# Created by: Raymond Chan
# for OPS535
# (c) 2016 - update for new wiki site
# (c) 2017 - update to prompt user to set the followings
#	     fqdn,ip for root name server
#	     email for dns admin
#	RNS_FQDN, RNS_IP, DNS_ADMIN_EMAIL
# (c) 2020 - update for the new wiki url
#
if [ -z "${RNS_FQDN}" ]
then
	echo "Please set the shell variable RNS_FQDN to the FQDN of your" >&2
	echo "root name server and run this script again." >&2
	exit 1
fi

if [ -z "${RNS_IP}" ]
then
	echo "Please set the shell variable RNS_IP to the IP address" >&2
        echo "of your root name server and run this script again." >&2
	exit 2
fi

if [ -z "${DNS_ADMIN_EMAIL}" ]
then
	echo "Please set the shell variable DNS_ADMIN_EMAIL to the" >&2
	echo "email address of your DNS administrator and run this" >&2
        echo "script again." >&2
	exit 3
fi
# start loading dns information from the web
url=https://wiki.cdot.senecacollege.ca/w/index.php/Domainreg

if [ ! -f raw.txt ]
then
	echo "Gettting wiki file from the web ..." >&2
	wget -O raw.txt $url
fi

buffer=$(cat raw.txt| grep ^'<td>')

nl=$(echo "$buffer"|wc -l)
a=0
b=6
# generating the zone file header
SN=$(date +%y%j%H) # yydddHH
echo "\$TTL 3600"
echo "@ IN SOA ${RNS_FQDN} ${DNS_ADMIN_EMAIL} (${SN} 1h 15m 30d 1h)"
echo "      IN NS ${RNS_FQDN}"
echo "${RNS_FQDN} IN A ${RNS_IP}"

while [ $a -lt $nl ]
do
	stuff=$(echo "$buffer"| head -"$b" | tail -5|nl|sed -e "s/<td>/x/g")
	#  echo "$stuff"
	fields=$(echo "$stuff"|sed -e "s/ //g"|awk -Fx {'print $2'})

	parameters=$(echo $fields)
	cc=$(echo $parameters | wc -w)
        # echo "paratest cc is $cc"

	if [ "$cc" -gt 0 ]
	then	
		#echo $a $parameters
		#read yyy	
		set $parameters
		if [ "$1" != "domainname" ]
		then
			if [ "$1" != "" -a "$3" != "" -a "$4" != "" ]
			then

	 			echo -e "${1}. \tIN \tNS \t$4."
	 			echo -e "${4}. \tIN \tA \t$3"
				echo " "
	
			fi
		fi
	fi

	let a=a+6
	let b=b+6

	#read xxx
done

Sample Output

$TTL 3600
@ IN SOA rns.cp.net. admin.cp.net. (1735109 1h 15m 30d 1h)
      IN NS rns.cp.net.
rns.cp.net. IN A 192.168.99.253
cp.net. 	IN 	NS 	ns.cp.net.
ns.cp.net. 	IN 	A 	192.168.99.1
 
Raymond.com. 	IN 	NS 	ns.raymond.com.
ns.raymond.com. 	IN 	A 	192.168.98.53
 
gcyao.net. 	IN 	NS 	pri-dns.gcyao.net.
pri-dns.gcyao.net. 	IN 	A 	192.168.33.53
 
bdgushue.com. 	IN 	NS 	pri-dns.bdgushue.com.
pri-dns.bdgushue.com. 	IN 	A 	192.168.14.53
 
dcwood.com. 	IN 	NS 	pri-dns.dcwood.com.
pri-dns.dcwood.com. 	IN 	A 	192.168.32.53
 
falli2.com. 	IN 	NS 	pri-dns.falli2.com.
pri-dns.falli2.com. 	IN 	A 	192.168.2.53
 
tnemat.com. 	IN 	NS 	a2-dns.tnemat.com.
a2-dns.tnemat.com. 	IN 	A 	192.168.25.53
 
accarneirobrandao.net. 	IN 	NS 	pri-dns.accarneirobrandao.net.
pri-dns.accarneirobrandao.net. 	IN 	A 	192.168.7.53