ipydns/iprenew
2019-01-31 18:57:55 -06:00

47 lines
1.4 KiB
Python
Executable File

#!/usr/bin/python
import re
import os
import sys
from datetime import datetime
FILE = "/etc/bind/example.com.db"
nip = sys.argv[1]
content = ';\n'\
'; BIND data file for local loopback interface\n'\
';\n'\
'$TTL 1800\n'\
'example.com. IN SOA ns1.example.com. hostmaster.example.com. (\n'\
' {0:%Y%m%d%H} ; Serial Remember change serial each time u edit the file\n'\
' 604800 ; Refresh\n'\
' 86400 ; Retry\n'\
' 2419200 ; Expire\n'\
' 604800 ) ; Negative Cache TTL\n'\
';\n'\
'example.com. 1800 IN NS ns1.example.com.\n'\
';\n'\
'ns1.example.com. IN A 0.0.0.0\n'\
'mailgw.example.com. IN A {1}}\n'\
';\n'\
';example.com. 60 IN A {0}}\n'\
'example.com. 60 IN A {1}\n'\
';\n'\
'example.com. 60 IN MX 0 example.com.\n'\
';\n'\
'ada 60 IN CNAME example.com.\n'\
'mydata 60 IN CNAME example.com.\n'\
'mail 60 IN CNAME example.com.\n'\
'www 43200 IN CNAME example.com.\n'\
'hditsv 43200 IN CNAME example.com.\n'\
'nextcloud 60 IN CNAME example.com.\n'\
'example.com. 60 IN TXT "v=spf1 mx -all"\n'.format(datetime.now(), nip)
if re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", nip):
os.remove(FILE)
with open(FILE, 'w')as f:
f.write(content)
os.system('rndc reload example.com')