From a2adf9ecab50a7059ac8317d200754c82d82ad0f Mon Sep 17 00:00:00 2001 From: cave beat Date: Tue, 15 Aug 2017 14:42:51 +0200 Subject: [PATCH] updated README, added command line Arguments. --- README.md | 33 ++++++++++++++++++++++++--------- src/gandi_live_dns.py | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 17 deletions(-) mode change 100644 => 100755 src/gandi_live_dns.py diff --git a/README.md b/README.md index 7d2aa9f..71d1796 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,11 @@ gandi_live_dns This is a simple dynamic DNS updater for the [Gandi](https://www.gandi.net) registrar. It uses their REST API to update -the zone file for a subdomain of a domain name to point at the external IPv4 +the zone file for a subdomain of a domain to point at the external IPv4 address of the computer it has been run from. It has been developed and tested on Debian 8 Jessie GNU/Linux using Python 2.7. -This DynDNS updater is inspired by https://github.com/jasontbradshaw/gandi-dyndns which worked very well -with the classic DNS from Gandi v4Website and their XML-RPC API. With the new v5 Website, Gandi has also launched a new REST API which makes it easier to communicate via bash/curl or python/requests. @@ -18,19 +16,36 @@ new REST API which makes it easier to communicate via bash/curl or python/reques You want your homeserver to be always available at `dynamic.mydomain.tld`. #### API Key -First, you must apply for an API key with Gandi. Visit -https://account.gandi.net/en/ and apply for (at least) the production API +First, you must apply for an API key with Gandi. Visit +https://account.gandi.net/en/ and apply for (at least) the production API key by following their directions. #### A Record Setup Create the DNS A Records in the GANDI Webinterface which you want to update if your IP changes. +#### Git Clone or Download the Script +Download the Script from [GitHub](https://github.com/cavebeat/gandi_live_dns/archive/master.zip) +or +`git clone https://github.com/cavebeat/gandi_live_dns.git` + #### Script Configuration -Then you'd need to configure the script. +Then you'd need to configure the script in the src directory. Copy `example.config.py` to `config.py`, and put it in the same directory as the script. - -yada yada ... -more to come \ No newline at end of file +#### Run the script + +Make the script executeable. + +` +$ cd gandi_live_dns/src +$ chmod +x gandi_live_dns.py +` +And run the script +` +$ ./gandi_live_dns.py +` + +This DynDNS updater is inspired by https://github.com/jasontbradshaw/gandi-dyndns which worked very well +with the classic DNS from Gandiv4 Website and their XML-RPC API. \ No newline at end of file diff --git a/src/gandi_live_dns.py b/src/gandi_live_dns.py old mode 100644 new mode 100755 index 9fa6491..bbcd4a8 --- a/src/gandi_live_dns.py +++ b/src/gandi_live_dns.py @@ -1,8 +1,10 @@ +#!/usr/bin/env python +# encoding: utf-8 ''' Gandi v5 LiveDNS - DynDNS Update via REST API and CURL/requests @author: cave -Licsense GPLv3 +License GPLv3 https://www.gnu.org/licenses/gpl-3.0.html Created on 13 Aug 2017 @@ -12,6 +14,7 @@ http://doc.livedns.gandi.net/#api-endpoint -> https://dns.beta.gandi.net/api/v5/ import requests, json import config +import argparse def get_dynip(ifconfig_provider): @@ -66,8 +69,14 @@ def update_records(uuid, dynIP, subdomain): return True -def main(): - +def main(force_update, verbosity): + + if force_update: + print "force update turned on" + if verbosity: + print "verbosity turned on" + + #get zone ID from Account uuid = get_uuid() @@ -75,15 +84,26 @@ def main(): dynIP = get_dynip(config.ifconfig) dnsIP = get_dnsip(uuid) - if dynIP == dnsIP: - print "IP Address match - no further action" - else: - print "IP Address mismatch - going to update the DNS Records for the subdomains" + if force_update: + print "Going to update the DNS Records for the subdomains" for sub in config.subdomains: update_records(uuid, dynIP, sub) + else: + if dynIP == dnsIP: + print "IP Address Match - no further action" + else: + print "IP Address Mismatch - going to update the DNS Records for the subdomains" + for sub in config.subdomains: + update_records(uuid, dynIP, sub) if __name__ == "__main__": - main() + parser = argparse.ArgumentParser() + parser.add_argument('-v', '--verbose', help="increase output verbosity", action="store_true") + parser.add_argument('-f', '--force', help="force an update", action="store_true") + args = parser.parse_args() + + + main(args.force, args.verbose)