Add test for existing DNS entry
The actions will only be performed now when the record actually needs to be changed.
This commit is contained in:
parent
ef1dd3f49b
commit
f3677cd314
2 changed files with 14 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ import logging
|
||||||
import sys
|
import sys
|
||||||
import configparser
|
import configparser
|
||||||
import argparse
|
import argparse
|
||||||
|
import dns.resolver
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format='%(levelname)s - %(message)s')
|
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format='%(levelname)s - %(message)s')
|
||||||
|
|
@ -21,6 +22,14 @@ def get_public_IP():
|
||||||
logging.info(f'The public IP address for this machine is: {public_ip}.')
|
logging.info(f'The public IP address for this machine is: {public_ip}.')
|
||||||
return public_ip
|
return public_ip
|
||||||
|
|
||||||
|
def resolve_name(domain):
|
||||||
|
logging.info(f'Resolving {domain}...')
|
||||||
|
result = dns.resolver.resolve(domain, 'A')
|
||||||
|
|
||||||
|
resolved_address = result[0].address
|
||||||
|
logging.info(f'Resolved {domain} to: {resolved_address}.')
|
||||||
|
return resolved_address
|
||||||
|
|
||||||
def get_zone_id(domain):
|
def get_zone_id(domain):
|
||||||
response = requests.get(f'https://api.cloudflare.com/client/v4/zones?name={domain}', headers=cloudflare_request_headers)
|
response = requests.get(f'https://api.cloudflare.com/client/v4/zones?name={domain}', headers=cloudflare_request_headers)
|
||||||
|
|
||||||
|
|
@ -72,6 +81,10 @@ fullDomainName = f'{subdomain}.{fixedTopLevelDomain}'
|
||||||
|
|
||||||
publicIP = get_public_IP()
|
publicIP = get_public_IP()
|
||||||
|
|
||||||
|
if resolve_name(fullDomainName) == publicIP:
|
||||||
|
logging.info(f'Currently resolved name already matches the public ip ({publicIP}), exiting...')
|
||||||
|
exit(0)
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(cloudflare_token_path)
|
config.read(cloudflare_token_path)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
requests==2.31.0
|
requests==2.31.0
|
||||||
|
dnspython==2.6.1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue