stecklars / dynamic-dns-netcup-api Goto Github PK
View Code? Open in Web Editor NEWA simple dynamic DNS client written in PHP for use with the netcup DNS API.
License: MIT License
A simple dynamic DNS client written in PHP for use with the netcup DNS API.
License: MIT License
Dear Lars,
I have a question about the scheduled execution of the script:
You mention in the README:
Missing
Caching the IP provided to netcup DNS, to avoid running into (currently extremely tolerant) rate limits in the DNS API
but recommend to run it every couple of minutes.
If the script detects that there was NO IP change (i.e. normally only once a day on enforced DSL reconnection), will it utilize the API to update the record (to the same value) or will it just skip it? In other words, whats a tolerable execution period to not spam the netcup API with unnecessary requests?
Your script is very helpful, thanks a lot!
Thanks for the script!
While using it, (via cron every 5 min) I get around every 5th time an API error:
[2022/11/07 00:10:04 +0100][ERROR] cURL Error: (22) The requested URL returned error: 504 - Exiting.
(sometimes other errors)
I am using the script with cronic, which sends me a mail every time the code produces output on stderr, which is desired, as you don't want to have cron jobs, which are more or less death since months but you do not see it, as you are not informed. But with the situation right now I get around 100 mails per day with error messages :-)
So I think, it would be nice to add a kind of an error counter (or timer) to the API calls and give it multiple retries over multiple calls?
What do you think?
Hallo,
jedes Mal, wenn ich das Script ausführe bekomme ich diesen Fehler:
"[ERROR] Error while logging in: Exiting."
Die Customer-Nummer ist korrekt, der API Key und das Passwort auch.
Woran kann es liegen?
Mit freundlichen Grüßen
Tim
Queries for IPv4 via api.ipify.org and for IPv6 via seeip.org often take some time since this service seems to be frequented very much, so I searched for an alternative. As an owner of a fritzbox router, I knew, that there should be some way to query this information directly. I found a solution here: https://wiki.ubuntuusers.de/FritzBox/Skripte/ , where variant 2 worked very well on my bash (Ubuntu 22.04 server behind fritzbox in cable network; assigning public ip4 ordered as option). Maybe we could take some load off the services api.ipify.org and seeip.org.
For IPv6 you will have to use the IP address of the host, since IPv6 does not use translation (i don't remember the correct term right now). Here I use the basic commands
hostname -I | cut -d " " -f 3
( in my case it's f 3, in others it might be f 2)
Another way to deal with multiple IPv6 addresses could be to filter out those starting with 'fd00' and 'fe80' since they are only local.
Unfortunately I have no php-skills, otherwise I would try to include these options into the functions.php. For now I use two little bash scripts when invoking './update'
Maybe we could help to take some load off the services api.ipify.org and seeip.org.
Hi Lars,
first of all thank you for this great tool!
Over the last few months I've been getting the following error when running the script as a cronjob:
Script Starting Oct 04, 2022 21:07.01
Full logs for this script are available at /blabla
[2022/10/04 21:07:01 +0200][NOTICE] =============================================
[2022/10/04 21:07:01 +0200][NOTICE] Running dynamic DNS client for netcup 3.0
[2022/10/04 21:07:01 +0200][NOTICE] This script is not affiliated with netcup.
[2022/10/04 21:07:01 +0200][NOTICE] =============================================
[2022/10/04 21:07:10 +0200][NOTICE] Logged in successfully!
[2022/10/04 21:07:10 +0200][NOTICE] Updating DNS records for domain "cptmynamesdomain.blabla"
[2022/10/04 21:07:15 +0200][NOTICE] Successfully received Domain info.
[2022/10/04 21:07:20 +0200][ERROR] Error while getting DNS Record info: The session id is not in a valid format. Exiting.
Script Finished Oct 04, 2022 21:07.20
Full logs for this script are available at /blabla
It has worked without problems before. If I run it manually via console this error only comes up about 50% of the time.
Any idea why this could be happening?
I'm running PHP 7.4.30 and curl 7.85.0 on Unraid 6.11.0. If you need more information feel free to ask!
EDIT: I have been trying around some more and it always seems to be working without errors if I launch the command twice in a row. The first run fails like above and the second one works. I have edited my cronjob to run it every hour at minute 7 and 8 and its working now. Maybe this helps someone...
Not sure, if I missed that option. It should be possible to specify the config file on the command line. In my personal hack it looks like this:
diff -urN dynamic-dns-netcup-api-master_mod_hilmar/functions.php dynamic-dns-netcup-api-master_mod_hilmar_orig/functions.php
--- dynamic-dns-netcup-api-master_mod_hilmar/functions.php 2021-10-23 14:53:58.036193565 +0200
+++ dynamic-dns-netcup-api-master_mod_hilmar_orig/functions.php 2018-06-10 05:27:20.000000000 +0200
@@ -1,6 +1,6 @@
<?php
-require_once $argv[1];
+require_once 'config.php';
//Declare possbile options
$quiet = false;
Yes, this is based on a old release.``
I'm using a cronjob to trigger your update.php and having problems since a few days
/etc/cron.d/netcup
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
*/5 * * * * root /usr/bin/php -f /opt/dynamic-dns-netcup-api/******/update.php > /var/log/netcup.log 2>&1
/var/log/netcup.log
PHP Warning: Use of undefined constant HOST - assumed 'HOST' (this will throw an Error in a future version of PHP) in /opt/dynamic-dns-netcup-api/******/update.php on line 11
PHP Warning: Use of undefined constant DOMAIN - assumed 'DOMAIN' (this will throw an Error in a future version of PHP) in /opt/dynamic-dns-netcup-api/******/update.php on line 11
[2021/01/22 11:40:01 +0100][NOTICE] Updating DNS records for host HOST on domain DOMAIN
PHP Warning: Use of undefined constant CUSTOMERNR - assumed 'CUSTOMERNR' (this will throw an Error in a future version of PHP) in /opt/dynamic-dns-netcup-api/******/update.php on line 14
PHP Warning: Use of undefined constant APIKEY - assumed 'APIKEY' (this will throw an Error in a future version of PHP) in /opt/dynamic-dns-netcup-api/******/update.php on line 14
PHP Warning: Use of undefined constant APIPASSWORD - assumed 'APIPASSWORD' (this will throw an Error in a future version of PHP) in /opt/dynamic-dns-netcup-api/******/update.php on line 14
PHP Warning: Use of undefined constant APIURL - assumed 'APIURL' (this will throw an Error in a future version of PHP) in /opt/dynamic-dns-netcup-api/******/functions.php on line 20
PHP Notice: Trying to access array offset on value of type null in /opt/dynamic-dns-netcup-api/******/functions.php on line 133
PHP Notice: Trying to access array offset on value of type null in /opt/dynamic-dns-netcup-api/******/functions.php on line 137
[2021/01/22 11:40:01 +0100][ERROR] Error while logging in: Exiting.
Already tried to change update.php and functions.php with the 'assumed' changes from PHP Notice. Returned into:
PHP Notice: Trying to access array offset on value of type null in /opt/dynamic-dns-netcup-api/******/functions.php on line 133
PHP Notice: Trying to access array offset on value of type null in /opt/dynamic-dns-netcup-api/******/functions.php on line 137
[2021/01/22 11:40:01 +0100][ERROR] Error while logging in: Exiting.
However, when I start the process by myself in a shell, it runs without any problem.
PHP Version 7.4 (tried 7.2 too)
Debian 10 (Buster)
Hello,
the script sets the *A Record to the IP Address, but unfortunately the @A record is not set.
Kind regards
Hi Lars, by the way: thanks for this great and helpful tool!
Since this morning running update.php throws following error:
php /home/johndoe/dynamic-dns-netcup-api/update.php [2022/10/22 07:45:45 +0200][NOTICE] =============================================
[2022/10/22 07:45:45 +0200][NOTICE] Running dynamic DNS client for netcup 3.0
[2022/10/22 07:45:45 +0200][NOTICE] This script is not affiliated with netcup.
[2022/10/22 07:45:45 +0200][NOTICE] =============================================
PHP Warning: file_get_contents(): Peer certificate CN=`johndoe.de' did not match expected CN=`api.ipify.org' in /home/johndoe/dynamic-dns-netcup-api/functions.php on line 142
PHP Warning: file_get_contents(): Failed to enable crypto in /home/johndoe/dynamic-dns-netcup-api/functions.php on line 142
PHP Warning: file_get_contents(https://api.ipify.org): Failed to open stream: operation failed in /home/johndoe/dynamic-dns-netcup-api/functions.php on line 142
[2022/10/22 07:45:45 +0200][WARNING] https://api.ipify.org didn't return a valid IPv4 address. Trying fallback API https://ip4.seeip.org
PHP Warning: file_get_contents(): Peer certificate CN=`johndoe.de' did not match expected CN=`ip4.seeip.org' in /home/johndoe/dynamic-dns-netcup-api/functions.php on line 152
PHP Warning: file_get_contents(): Failed to enable crypto in /home/johndoe/dynamic-dns-netcup-api/functions.php on line 152
PHP Warning: file_get_contents(https://ip4.seeip.org): Failed to open stream: operation failed in /home/johndoe/dynamic-dns-netcup-api/functions.php on line 152
[2022/10/22 07:45:45 +0200][ERROR] Main API and fallback API didn't return a valid IPv4 address. Exiting.
Checking https://www.ipify.org/ it seems that their API URL changed from https://api.ipify.org to https://api64.ipify.org.
So I modified functions.php on line 142 accordingly from:
$publicIP = rtrim(file_get_contents('https://api.ipify.org'));
to
$publicIP = rtrim(file_get_contents('https://api64.ipify.org'));
and the update ran fine again!
As you see I'm still using version 3.0, but there is still the old Api URL in functions.php of the latest release (v 3.0.1)
The code quality in the curl retry logic is pretty bad. It works, but it needs to be improved and reworked.
Maybe the issue is related to #21 . I just noticed that seeip changed the URL's to read out the IPv4 / IPv6 addresses. They now read https://ipv4.seeip.org & https://ipv6.seeip.org. I noticed the messages:
[2023/01/25 08:16:02 +0100][WARNING] https://ip6.seeip.org didn't return a valid IPv6 address.
in the log, which are gone after fixing the URL in functions.php. Thanks for your work!
Hallo,
Wenn ich mir überlege, was für Stunts ich machen wollte um ein DYNDNS auf netcup nachzubilden - bevor ich über dieses repo gestolpert bin - wollte ich einfach mal DANKE sagen.
Hat sofort funktioniert!
Gruß
Michael
Hi,
thank you very much for your script. I just installed it and it worked right away without any hassle.
I'm wondering how to set up updating multiple subdomain on different domains though. If I get it right the logic of the config.php doesn't provide that. Or am I supposed to use multiple folders with their own configs for different subdomains and call their update.php's with their own cron jobs?
For clarification, I want to update subdomains like this from one machine:
aaa.bbbbb.de
ccc.ddddd.de
Thank you again
Hi,
I run your awesome script on my home server behind a fritzbox and it works perfectly for IPv6. But IPv6 is faulty: The script detects the IPv6 address of my server and not the public address of my fritzbox.
Til now I'm not very familiar with ipv6 but I'm not sure wether it is possible to get the public ip address of the router by calling an external web site (as it is done by ipv4) in generally?
BTW: The URL https://ip6.seeip.org in the script seems not to be worked anymore (access forbidden), perhaps it would be a good solution to use https://api64.ipify.org (similar to the ipv4 url)?
Kind regards
Martin
Hi,
It seems there is an issue accessing https://api.ipify.org...
When I execute the script, I get a message:
"cURL Error while accessing https://api.ipify.org/: (7) Failed to connect to api.ipify.org port 443: Connection refused - Retrying in 30 seconds."
even trying to access ipify.org from a browser is not possible.
Does somebody know what the issue of that is, and how to solve it?
Thanks!
Add #!/usr/bin/env php
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.