danamir / dyn-gandi Goto Github PK
View Code? Open in Web Editor NEWUse Gandi LiveDNS API to update DNS records with a dynamic IP.
License: GNU General Public License v3.0
Use Gandi LiveDNS API to update DNS records with a dynamic IP.
License: GNU General Public License v3.0
Hi,
I would like to do something like that :
from dyn_gandi.dyn_gandi import *
class my_class():
def __init__():
parse_options()
parse_configuration()
def do_something(self):
livedns_handle()
Currently to do that, it looks like i am forced to add the lib directly in my code.
I tried to add it with pip install -r requirements, where i put git+https://github.com/Danamir/dyn-gandi.git
But when i am looking in my venv, there is no code in the dyn-gandi path.
Thx for help.
I'm unable to get the script running. It says the domain doesn't exist although it does:
screenshoot of DNS records
mini:dyn-gandi-1.0 cedadmin$ uname -rs
Darwin 10.8.0
mini:dyn-gandi-1.0 cedadmin$ python3 dyn_gandi.py -d
Resolved IP: 95.140.125.30
Wrote 95.140.125.30 to ip.txt file.
Domain: cirdec.com
Records: cloud/A
Requests: method=GET url=https://dns.api.gandi.net/api/v5/domains/cirdec.com headers=None json={'x-api-key': '************************', 'Accept': 'application/json'}
2019-04-11 12:54:08 - LiveDNS error: The domain cirdec.com does not exist. [ERROR]
2019-04-11 12:54:08 - LiveDNS error: The domain cirdec.com does not exist. [ERROR]
Hi
First at all thanks for this usefull program.
Everything works fine expect for one kind of type
The ip address doesn't change for a TXT type :
@ | TXT | 3600 | "v=spf1 a mx ip4:83.XX.XXX.XXX -all"
Is it possible ?
Thanks
Hi,
FYI I updated your script to match correct header for authentication with latest API changes:
diff --git a/livedns_client.py b/livedns_client.py
index 01e5492..49d243e 100644
--- a/livedns_client.py
+++ b/livedns_client.py
@@ -37,8 +37,7 @@ class LiveDNSClient:
url = "%s%s" % (self.url, urllib.parse.quote(query))
headers = {
- "x-api-key": self.key,
- "Authorization": "Bearer %s" % self.key,
+ "Authorization": "Apikey %s" % self.key,
"Accept": "application/json",
}
It was requited to avoid LiveDNS error: The domain does not exist. [ERROR]
.
Hi
I'm trying your script with my domain hosted on new V5 Gandi platform but I'm not sure syntax to use to indicate the specific A records I want to update in my domain. I don't see any examples in README neither in the config file included :(
Thanks for explanations ;)
Vincèn
I installed this on a Raspberry Pi, if for example I have a power failure.. Does the script run on to the start?
(I am debuting developing)
Thank 🙃
Using more than one record configured, the update make nothing when the first record has the same IP (unchanged).
file "dyn_gandi.py" @ line 92
dns_ip = r_record['values'][0]
Hello,
Sorry I'm very basic in Python.
I install your program in my server, and I log this log:
running install
running bdist_egg
running egg_info
writing requirements to dyn_gandi.egg-info/requires.txt
writing dyn_gandi.egg-info/PKG-INFO
writing top-level names to dyn_gandi.egg-info/top_level.txt
writing dependency_links to dyn_gandi.egg-info/dependency_links.txt
writing entry points to dyn_gandi.egg-info/entry_points.txt
reading manifest file 'dyn_gandi.egg-info/SOURCES.txt'
writing manifest file 'dyn_gandi.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
warning: install_lib: 'build/lib' does not exist -- no Python modules to install
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying dyn_gandi.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying dyn_gandi.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying dyn_gandi.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying dyn_gandi.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying dyn_gandi.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
copying dyn_gandi.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying dyn_gandi.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
creating 'dist/dyn_gandi-1.0-py2.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing dyn_gandi-1.0-py2.7.egg
removing '/usr/lib/python2.7/site-packages/dyn_gandi-1.0-py2.7.egg' (and everything under it)
creating /usr/lib/python2.7/site-packages/dyn_gandi-1.0-py2.7.egg
Extracting dyn_gandi-1.0-py2.7.egg to /usr/lib/python2.7/site-packages
dyn-gandi 1.0 is already the active version in easy-install.pth
Installing dyn_gandi script to /usr/bin
Installed /usr/lib/python2.7/site-packages/dyn_gandi-1.0-py2.7.egg
Processing dependencies for dyn-gandi==1.0
Searching for requests==2.10.0
Best match: requests 2.10.0
Adding requests 2.10.0 to easy-install.pth file
Using /usr/local/lib/python2.7/site-packages
Searching for docopt==0.6.2
Best match: docopt 0.6.2
Processing docopt-0.6.2-py2.7.egg
docopt 0.6.2 is already the active version in easy-install.pth
Using /usr/lib/python2.7/site-packages/docopt-0.6.2-py2.7.egg
Finished processing dependencies for dyn-gandi==1.0
then when I processing dyn_gandi, I got "command not found".
Thanks,
Running into an issue with a .co.uk domain. In dyn_gandi.py line 186-189 your regex thinks that .co.uk is a subdomain. So for example if I had test.co.uk dyn_gandi.py seems to think that 'co.uk' is the domain and discards 'test'.
Thanks for the great tool btw
I've created the files needed to create a Debian package. I had to refactor the project to have my package working.
Not sure you'll be interested in these changes. You can have a look at my fork : https://github.com/pipoprods/dyn-gandi
Let me know if you want a PR of this.
Hi,
FYI, I reinstalled dyn-gandi with the latest version on a debian 11 distrib a few days ago, and it was not working any more:
# /usr/local/bin/dyn_gandi -c config.ini.dontpanic.org
2021-12-14 10:40:08 - LiveDNS error: The domain dontpanic.org does not exist. [ERROR]
2021-12-14 10:40:08 - LiveDNS error: The domain dontpanic.org does not exist. [ERROR]
But I found out how to fix it:
--- livedns_client.py- 2021-05-22 02:10:47.000000000 +0200
+++ livedns_client.py+ 2021-12-14 10:28:02.575820269 +0100
@@ -37,6 +37,7 @@
url = "%s%s" % (self.url, urllib.parse.quote(query))
headers = {
+ "x-api-key": self.key,
"Authorization": "Apikey %s" % self.key,
"Accept": "application/json",
}
Now it works like a charm:
# /usr/local/bin/dyn_gandi -c config.ini.dontpanic.org
2021-12-14 10:41:52 - Local IP: 86.252.39.142, DNS IP: 86.252.39.142 [OK]
Here's my config file:
[api]
url = https://dns.api.gandi.net/api/v5
; Generate your Gandi API key via : https://account.gandi.net/en/users/<user>/security
key = ******
[dns]
domain = dontpanic.org
; comma-separated records list
records = @,www
ttl = 3600
[ip]
; Choose an IP resolver : either plain text, or web page containing a single IP
resolver_url = http://ipecho.net/plain
; resolver_url = http://ifconfig.me/ip
; resolver_url = http://www.mon-ip.fr
; Optional alternative IP resolver, called on timeout
resolver_url_alt =
I have no real clue what the issue was, though :-)
Rgds
Hi, it looks like gandi have changed their api slightly, and you get a uuid for a snapshot now, not an id, breaking the script. To fix you need to essentially revert commit e138537 AND change the array identifier from id to uuid:
diff -u -r --ignore-all-space --ignore-blank-lines dyn-gandi/dyn_gandi.py dyn-gandi-new/dyn_gandi.py
--- dyn-gandi/dyn_gandi.py 2021-12-21 07:14:30.271970535 +0000
+++ dyn-gandi-new/dyn_gandi.py 2021-12-21 07:07:16.000000000 +0000
@@ -118,10 +118,10 @@
if r_snap is None:
raise RuntimeWarning("Could not create snapshot." % domain)
- snapshot_id = r_snap['id']
+ snapshot_uuid = r_snap['uuid']
if verbose:
- print("Backup snapshot created, id: %s." % snapshot_id)
+ print("Backup snapshot created, uuid: %s." % snapshot_uuid)
# update DNS records
for rec in records:
@@ -129,14 +129,14 @@
r_update = ldns.put_domain_record(domain=domain, record_name=rec['name'], record_type=rec['type'], value=ip, ttl=int(config['dns']['ttl']))
except Exception as e:
print(
- "%s, Error: %s. Backup snapshot id: %s."
- % (message, repr(e), snapshot_id),
+ "%s, Error: %s. Backup snapshot uuid: %s."
+ % (message, repr(e), snapshot_uuid),
file=sys.stderr,
)
raise e
if r_update is None:
- message = "%s, Error when updating: %s/%s. Backup snapshot id: %s." % (message, rec['name'], rec['type'], snapshot_id)
+ message = "%s, Error when updating: %s/%s. Backup snapshot uuid: %s." % (message, rec['name'], rec['type'], snapshot_uuid)
return "ERROR", message
if verbose:
@@ -144,7 +144,7 @@
print("API response: %s" % json.dumps(r_update, indent=2))
# delete snapshot
- ldns.delete_domain_snapshot(domain, sid=snapshot_id)
+ ldns.delete_domain_snapshot(domain, sid=snapshot_uuid)
if verbose:
print("Backup snapshot deleted.")
Hope this helps someone, also note that you will need to include to diff from issue#27 (including the "x-api-key": self.key,
field in the headers in livedns_client.py
) such as:
diff -u -r --ignore-all-space --ignore-blank-lines dyn-gandi/livedns_client.py dyn-gandi-new/livedns_client.py
--- dyn-gandi/livedns_client.py 2021-12-21 07:14:30.271970535 +0000
+++ dyn-gandi-new/livedns_client.py 2021-12-21 07:02:53.000000000 +0000
@@ -37,6 +37,7 @@
url = "%s%s" % (self.url, urllib.parse.quote(query))
headers = {
+ "x-api-key": self.key,
"Authorization": "Apikey %s" % self.key,
"Accept": "application/json",
}
to also make the updater work again
Yours
Alex
Hello
Gandyn does not work anymore, this is the exit of the terminal.
If someone has an idea ?
Thank you
Traceback (most recent call last): File "/home/ignace/Téléchargements/gandyn/gandyn-master/src/dyn-gandi-master/.env/bin/dyn_gandi", line 11, in <module> load_entry_point('dyn-gandi==1.0', 'console_scripts', 'dyn_gandi')() File "/home/ignace/Téléchargements/gandyn/gandyn-master/src/dyn-gandi-master/.env/lib/python3.7/site-packages/pkg_resources/__init__.py", line 480, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/home/ignace/Téléchargements/gandyn/gandyn-master/src/dyn-gandi-master/.env/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2693, in load_entry_point return ep.load() File "/home/ignace/Téléchargements/gandyn/gandyn-master/src/dyn-gandi-master/.env/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2324, in load return self.resolve() File "/home/ignace/Téléchargements/gandyn/gandyn-master/src/dyn-gandi-master/.env/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2330, in resolve module = __import__(self.module_name, fromlist=['__name__'], level=0) ModuleNotFoundError: No module named 'dyn_gandi'
Hi
I have to keep editing the code to add support for org.uk :
diff -u -r --ignore-all-space --ignore-blank-lines dyn-gandi/dyn_gandi.py dyn-gandi-new/dyn_gandi.py
--- dyn-gandi/dyn_gandi.py 2021-12-21 07:14:30.271970535 +0000
+++ dyn-gandi-new/dyn_gandi.py 2021-12-21 07:07:16.000000000 +0000
@@ -190,11 +190,13 @@
# Sub-domain check
domain = domain.replace(".co.uk", ".co_uk")
+ domain = domain.replace(".org.uk", ".org_uk")
if re.match(r"^.+\.[^.]+\.[^.]+$", domain):
if verbose:
print("Warning: removing sub-domain part of %s" % domain)
domain = re.sub(r"^.+\.([^.]+\.[^.]+)$", r"\g<1>", domain)
domain = domain.replace(".co_uk", ".co.uk")
+ domain = domain.replace(".org_uk", ".org.uk")
if verbose:
print("Domain: %s" % domain)
which is annoying when I have to do a git pull for a new version, and re-add it. Could you please add this into the updater?
Thank you for your great script.
Alex
Hi,
i try to update a record in my domain, but script modifies '@' record instead, and this must not happen. If i delete '@' record in config.ini
, i have an error :
My config.ini :
cat /etc/dyn-gandi/config.ini
[api]
url = https://dns.api.gandi.net/api/v5
; Generate your Gandi API key via : https://account.gandi.net/en/users//security
key = secret
[dns]
domain = mydomain
; comma-separated records list
records = myrecord
ttl = 3600
[ip]
; Choose an IP resolver : either plain text, or web page containing a single IP
resolver_url = http://ipecho.net/plain
; resolver_url = http://ifconfig.me/ip
; resolver_url = http://www.mon-ip.fr
; Optional alternative IP resolver, called on timeout
resolver_url_alt =
/usr/local/bin/dyn_gandi -c /etc/dyn-gandi/config.ini --dry-run
Resolved IP: 1.2.3.4
Domain: mydomain
Records: myrecord/A
2019-10-18 14:20:22 - LiveDNS error: Main record not found to check DNS IP for domain mydomain. [ERROR]
2019-10-18 14:20:22 - LiveDNS error: Main record not found to check DNS IP for domain mydomain. [ERROR]
If i add @ to the record variable, there's no error but script modify my '@' record, this is not wanted.
records = @,myrecord
/usr/local/bin/dyn_gandi -c /etc/dyn-gandi/config.ini --dry-run
Resolved IP: 1.2.3.4
Domain: mydomain
Records: @/A, myrecord/A
======== Dry run ========
Would update records:
@/A from 10.11.12.13 to 1.2.3.4 <= WRONG, must not modify
myrecord/A from None to 1.2.3.4
=========================
2019-10-18 14:07:55 - Local IP: 1.2.3.4, DNS IP:10.11.12.13 [DRY RUN]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.