Last active
November 1, 2016 16:53
-
-
Save s4mdf0o1/e02a8b6ebdacd0f74a8b834479e17a7a to your computer and use it in GitHub Desktop.
Change your authoritative DNS Serial
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 python | |
import os | |
import re | |
import time | |
file = "<put/your/db.domain.tld/zone/file/here>" | |
date = time.strftime("%Y%m%d") | |
regex = r"^( *)(20[0-9]{6})([0-9]{2}) ; Serial" | |
new_date = "" | |
with open(file) as fp: | |
with open(file+'.tmp','w') as dest: | |
for line in fp.readlines(): | |
if re.match(regex, line): | |
#print "match" | |
rgx = re.match(regex, line) | |
nb_spaces = rgx.group(1) | |
last_date = rgx.group(2) | |
last_serial = rgx.group(3) | |
if last_date != date: | |
new_date = date | |
serial="01" | |
else: | |
new_date = last_date | |
serial = int(last_serial) + 1 | |
if serial < 10: | |
serial = "%02d" % (serial,) | |
print nb_spaces + new_date + serial + ' ; Serial' | |
dest.write(nb_spaces + new_date + serial + ' ; Serial'+'\n') | |
else: | |
#pass | |
print line.strip('\n') | |
dest.write(line) | |
print "$ diff <put/your/db.domain.tld/zone/file/here>{,.tmp}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your file dns-db-zone, should look like :
for bind9/nsd