Last active
February 12, 2022 14:14
-
-
Save alainwolf/7cdfc502a16c830652093d4b2bcfab47 to your computer and use it in GitHub Desktop.
Compare Domain Serials of hidden primary server with public servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Compare Domain Serials of hidden primary server with public servers | |
# | |
# Our hidden primary server | |
_PRIMARY_SERVER="dns0.example.net." | |
# The domain to query | |
_domain="$1" | |
# List of public "secondary" servers | |
_public_servers="$( dig +short NS "$_domain" |sort )" | |
# The current Year (start of the domain serial number) | |
_cur_year="$( date +%Y )" | |
# Regular expression to extract serial number from SOA record | |
_expr="${_cur_year}[0-9]{6}(?=[^0-9])" | |
# SOA record from the hidden primary server | |
_primary_soa=$( dig +short +nosplit "@${_PRIMARY_SERVER}" -t SOA -q "$_domain" ) | |
# Extract serial from hidden primary SOA record | |
primary_serial=$( echo "$_primary_soa" | grep -Po "$_expr" ) | |
# Print out the result | |
printf 'Primary: %18s \t %s \n' "*** hidden ***" "$primary_serial" | |
# Loop trough public "secondary" servers | |
for _server in ${_public_servers}; do | |
# SOA record from the public server | |
_public_soa=$( dig +short +nosplit "@${_server}" -t SOA -q "$_domain" ) | |
# Extract serial from the public servers SOA record | |
_public_serial=$( echo "$_public_soa" | grep -Po "$_expr" ) | |
# Print out the result | |
printf 'Public: %18s \t %s \n' "$_server" "$_public_serial" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment