add support dns.he.net
This commit is contained in:
parent
abcb8a6c8e
commit
acde2b966b
|
@ -249,11 +249,14 @@ Example usage in cron with Python:
|
|||
```shell
|
||||
# at 00:00 on Monday
|
||||
0 0 * * 1 /usr/bin/python3 ~/simplewc.py --domain EXAMPLE.COM --server 8.8.8.8 --keyname KEY --keydata YOU_KEY_CONTENT > /dev/null
|
||||
# 00:00 on day-of-month 1 and 15
|
||||
0 0 1,15 * * /usr/bin/python3 ~/simplewc.py --domain EXAMPLE.COM --server dyn.dns.he.net --keyname - --keydata YOU_DDNSKEY > /dev/null
|
||||
```
|
||||
Example usage in terminal with make the script executable:
|
||||
```shell
|
||||
chmod u+x ./simplewc.py
|
||||
./simplewc.py --domain EXAMPLE.COM --server 8.8.8.8 --keyname KEY --keydata YOU_KEY_CONTENT --test --force
|
||||
./simplewc.py --domain EXAMPLE.COM --server dyn.dns.he.net --keyname - --keydata YOU_DDNSKEY --test --force
|
||||
```
|
||||
|
||||
____
|
||||
|
|
35
simplewc.py
35
simplewc.py
|
@ -6,6 +6,7 @@ from shutil import make_archive
|
|||
from subprocess import Popen, PIPE, STDOUT
|
||||
from time import sleep
|
||||
from typing import Union
|
||||
import urllib.request
|
||||
try:
|
||||
from dns import resolver, rdatatype, rdataclass, rdata, update, query, tsigkeyring, tsig, name
|
||||
except ModuleNotFoundError:
|
||||
|
@ -66,6 +67,35 @@ class NSupdate:
|
|||
return query.tcp(q=rec_upd, where=self._server)
|
||||
|
||||
|
||||
class HEupdate:
|
||||
"""
|
||||
Dynamic DNS update on dyn.dns.he.net from Python
|
||||
"""
|
||||
def __init__(self, ddnskey: str, server: str = 'https://dyn.dns.he.net/nic/update') -> None:
|
||||
"""
|
||||
Object constructor
|
||||
:param ddnskey: string with content of the key (password) to update the record
|
||||
:param server: string with server for dynamic update request
|
||||
"""
|
||||
self._server = server
|
||||
self._ddnskey = ddnskey
|
||||
|
||||
def rec_add(self, rec_key: str, rec_val: str) -> None:
|
||||
"""
|
||||
Change record data from DNS zone
|
||||
:param rec_key: string with record fqdn
|
||||
:param rec_val: string with record value
|
||||
:return: None, Message after request
|
||||
"""
|
||||
self._data = 'hostname=' + rec_key + '&' + 'password=' + self._ddnskey + '&' + 'txt=' + rec_val
|
||||
request = urllib.request.Request(url=self._server, data=bytes(self._data.encode('utf-8')), method='POST')
|
||||
response = urllib.request.urlopen(request).read()
|
||||
if response.startswith(b'\xff\xd8'):
|
||||
return response
|
||||
else:
|
||||
return str(response.decode('utf-8'))
|
||||
|
||||
|
||||
class ACMEcert:
|
||||
"""
|
||||
ACME launcher for DNS-01 challenge from Python
|
||||
|
@ -166,7 +196,10 @@ if __name__ == "__main__":
|
|||
cer_test = True
|
||||
|
||||
cer = ACMEcert(zone=args['domain'], acme_path=args['acmepath'], force=cer_force, test=cer_test)
|
||||
dns = NSupdate(zone=args['domain'], server=args['server'], keyname=args['keyname'], keydata=args['keydata'])
|
||||
if 'dns.he.net' in args['server']:
|
||||
dns = HEupdate(ddnskey=args['keydata'])
|
||||
else:
|
||||
dns = NSupdate(zone=args['domain'], server=args['server'], keyname=args['keyname'], keydata=args['keydata'])
|
||||
|
||||
attempts_pass, attempts_wait = 0, 60
|
||||
while attempts_pass < 2:
|
||||
|
|
Loading…
Reference in New Issue
Block a user