diff --git a/dyndns/domain_update.py b/dyndns/domain_update.py index 81919c6..9355611 100644 --- a/dyndns/domain_update.py +++ b/dyndns/domain_update.py @@ -27,16 +27,21 @@ def main(domain, settings='settings.txt'): return "Domain {} configured incorectly. Rerun setup.".format(domain) print("Read {} config.".format(domain)) - # read existing ip for domain + # read existing ip for domain from config || from DNS if last check was less than 60 sec ago ip = None - try: - answers = dns.resolver.query(domain, 'A') - if not answers: - return "No A record found for domain {}".format(domain) - ip = answers[0] - print("IP {} found in A record".format(ip)) - except Exception: - print("No A record found for domain {}".format(domain)) + if 'last_success' in config[domain] and int(time.time()) - config[domain]['last_success'] < 60: + ip = config[domain]['ip'] + print("Recently used IP {}".format(ip)) + else: + try: + answers = dns.resolver.query(domain, 'A') + if not answers: + return "No A record found for domain {}".format(domain) + ip = answers[0] + print("IP {} found in A record".format(ip)) + config[domain]['last_dns_check'] = int(time.time()) + except Exception: + print("No A record found for domain {}".format(domain)) # get public ip response = requests.get("https://api.ipify.org", params={'format': 'json'}) @@ -46,8 +51,6 @@ def main(domain, settings='settings.txt'): if not public_ip: return "Could not discover public IP." - config[domain]['last_dns_check'] = int(time.time()) - print("New IP: {}".format(public_ip)) if ip and str(ip) == str(public_ip): config[domain]['ip'] = public_ip diff --git a/setup.py b/setup.py index 26262ac..cf18f83 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name = 'domain-connect-dyndns', - version = '0.0.2', + version = '0.0.3', description = 'Python client library for Dynamic DNS using Domain Connect', license = 'MIT', long_description=long_description,