From 64aa58b270864608bc7c5120687448ab0a3f56b8 Mon Sep 17 00:00:00 2001 From: zhangshaozhou402 Date: Fri, 22 Jun 2018 16:27:27 +0800 Subject: [PATCH 1/3] add support for domain to domain mode --- src/example.config.py | 14 ++++++++++---- src/gandi-live-dns.py | 29 +++++++++++++++++------------ 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/example.config.py b/src/example.config.py index 7ac37fc..8775ce6 100644 --- a/src/example.config.py +++ b/src/example.config.py @@ -20,7 +20,7 @@ ''' api_endpoint = 'https://dns.api.gandi.net/api/v5' -#your domain with the subdomains in the zone file/UUID +#your domain with the subdomains in the zone file/UUID domain = 'mydomain.tld' #enter all subdomains to be updated, subdomains must already exist to be updated @@ -29,13 +29,13 @@ #300 seconds = 5 minutes ttl = '300' -''' -IP address lookup service +''' +IP address lookup service run your own external IP provider: + https://github.com/mpolden/ipd + -e.g. +e.g. + https://ifconfig.co/ip + http://ifconfig.me/ip + http://whatismyip.akamai.com/ @@ -43,3 +43,9 @@ + many more ... ''' ifconfig = 'choose_from_above_or_run_your_own' + + +''' +Target domain you wish to update your domain to. +''' +target_domain = 'target_domain_you_wish' diff --git a/src/gandi-live-dns.py b/src/gandi-live-dns.py index 55e5757..5deff40 100755 --- a/src/gandi-live-dns.py +++ b/src/gandi-live-dns.py @@ -15,7 +15,14 @@ import requests, json import config import argparse +import socket +def get_DomainIp(target_domain): + ''' Get IPv4 of target domainself. + This is the IP address of another domain you wish to update your own domain to + ''' + ipaddress = socket.getaddrinfo(target_domain,'http')[0][4][0] + return ipaddress.strip('\n') def get_dynip(ifconfig_provider): ''' find out own IPv4 at home <-- this is the dynamic IP which changes more or less frequently @@ -89,7 +96,7 @@ def update_records(uuid, dynIP, subdomain): -def main(force_update, verbosity): +def main(force_update, verbosity, d2dmode): if verbosity: print "verbosity turned on - not implemented by now" @@ -97,11 +104,14 @@ def main(force_update, verbosity): #get zone ID from Account uuid = get_uuid() - - #compare dynIP and DNS IP - dynIP = get_dynip(config.ifconfig) + + #compare dynIP and DNS IP + if d2dmode: + dynIP = get_DomainIp(config.target_domain) + else: + dynIP = get_dynip(config.ifconfig) dnsIP = get_dnsip(uuid) - + if force_update: print "Going to update/create the DNS Records for the subdomains" for sub in config.subdomains: @@ -118,13 +128,8 @@ def main(force_update, verbosity): parser = argparse.ArgumentParser() parser.add_argument('-v', '--verbose', help="increase output verbosity", action="store_true") parser.add_argument('-f', '--force', help="force an update/create", action="store_true") + parser.add_argument('-d', '--d2d', help="domain to domain mode", action="store_true") args = parser.parse_args() - - - main(args.force, args.verbose) - - - - + main(args.force, args.verbose, args.d2dmode) From 3959d393ea4b4d60f165f30408623e445b52ea71 Mon Sep 17 00:00:00 2001 From: Will Stark <11699706@qq.com> Date: Fri, 22 Jun 2018 20:38:18 +0800 Subject: [PATCH 2/3] argument fix --- src/gandi-live-dns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gandi-live-dns.py b/src/gandi-live-dns.py index 5deff40..40e0850 100755 --- a/src/gandi-live-dns.py +++ b/src/gandi-live-dns.py @@ -132,4 +132,4 @@ def main(force_update, verbosity, d2dmode): args = parser.parse_args() - main(args.force, args.verbose, args.d2dmode) + main(args.force, args.verbose, args.d2d) From 12dcdb9b511a9bfeeb0795623b0c6d5833e587c5 Mon Sep 17 00:00:00 2001 From: Will Zhang Date: Mon, 9 Jul 2018 10:38:48 +0800 Subject: [PATCH 3/3] Update gandi-live-dns.py update get domain ip function --- src/gandi-live-dns.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gandi-live-dns.py b/src/gandi-live-dns.py index 40e0850..ea8d6d9 100755 --- a/src/gandi-live-dns.py +++ b/src/gandi-live-dns.py @@ -21,8 +21,8 @@ def get_DomainIp(target_domain): ''' Get IPv4 of target domainself. This is the IP address of another domain you wish to update your own domain to ''' - ipaddress = socket.getaddrinfo(target_domain,'http')[0][4][0] - return ipaddress.strip('\n') + ipaddress = socket.gethostbyname(target_domain) + return ipaddress def get_dynip(ifconfig_provider): ''' find out own IPv4 at home <-- this is the dynamic IP which changes more or less frequently