Giter Club home page Giter Club logo

dynamic-dns-netcup-api's Introduction

Dynamic DNS client for netcup DNS API

This project is not affiliated with the company netcup GmbH. Although it is developed by an employee, it is not an official client by netcup GmbH and was developed in my free time. netcup is a registered trademark of netcup GmbH, Karlsruhe, Germany.

A simple dynamic DNS client written in PHP for use with the netcup DNS API.

Requirements

  • Be a netcup customer: https://www.netcup.de – or for international customers: https://www.netcup.eu
    • You don't have to be a domain reseller to use the necessary functions for this client – every customer with a domain may use it.
  • netcup API key and API password, which can be created within your CCP at https://www.customercontrolpanel.de
  • PHP-CLI with CURL extension
  • A domain 😉

Features

Implemented

  • All necessary API functions for DNS actions implemented (REST API)
  • Determines correct public IP address, uses fallback API for determining the IP address, in case main API does return invalid / no IP
  • Automatically retries API requests on errors
  • IPv4 and IPv6 Support (can be individually enabled / disabled)
  • Possible to manually provide IPv4 / IPv6 address to set as a CLI option
  • Update everything you want in one go: Every combination of domains, subdomains, domain root, and domain wildcard is possible
  • Creation of DNS record, if it doesn't already exist
  • If configured, lowers TTL to 300 seconds for the domain on each run, if necessary
  • Hiding output (quiet option)

Missing

  • Caching the IP provided to netcup DNS, to avoid running into (currently extremely tolerant) rate limits in the DNS API
  • Probably a lot more 😁 – to be continued...

Getting started

Download

Download the latest version from the releases or clone the repository:

$ git clone https://github.com/stecklars/dynamic-dns-netcup-api.git

I'm always trying to keep the master branch stable.

Then, allow update.php to be executed by your user:

chmod u+x update.php

Configuration

Configuration is very simple:

  • Copy config.dist.php to config.php
    • cp config.dist.php config.php
  • Fill out config.php with the required values. The options are explained in there.

How to use

./update.php

You should probably run this script every few minutes, so that your IP is updated as quickly as possible. Add it to your cronjobs and run it regularly, for example every five minutes.

CLI options

Just add these Options after the command like ./update.php --quiet

short option long option function
-q --quiet The script won't output notices, only errors and warnings
-c --config Manually provide a path to the config file
-4 --ipv4 Manually provide the IPv4 address to set
-6 --ipv6 Manually provide the IPv6 address to set
-h --help Outputs this help
-v --version Outputs the current version of the script

If you have ideas on how to improve this script, please don't hesitate to create an issue. Thank you!

dynamic-dns-netcup-api's People

Contributors

hecke29 avatar henningkerstan avatar hpreusse avatar ipf avatar jypdwhite avatar n-thumann avatar stecklars avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dynamic-dns-netcup-api's Issues

error accessing api.ipify.org

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!

"Error while logging in: Exiting."

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

Error while getting DNS Record info: The session id is not in a valid format.

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...

Cronjob throwing PHP Warnings and can't login

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)

Danke!

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

Question about execution schedule

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!

@A record not set

Hello,

the script sets the *A Record to the IP Address, but unfortunately the @A record is not set.

Kind regards

Support multiple domains

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

query IPv4 directly from Fritzbox if available

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.

API didn't return a valid IPv4 addres

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)

Retry API errors?

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?

Wrong IPv6?

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

Specify config files on command line

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.``

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.