madbob / manydns
多个动态DNS提供商的包装器
0.2
2022-12-22 10:15 UTC
This package is auto-updated.
Last update: 2024-09-22 14:30:07 UTC
README
此包封装了多个不同动态DNS提供商的更新API。
目前支持的服务提供商
- NoIP https://www.noip.com/
- ChangeIP http://www.changeip.com/
- Dynu https://www.dynu.com/
- DuckDNS https://www.duckdns.org/
安装
composer require madbob/manydns
用法
require 'vendor/autoload.php'; use ManyDNS\ManyDNS; use ManyDNS\FailedUpdateException; /* To obtain a list of supported providers */ $providers = ManyDNS::getProviders(); foreach($providers as $provider) { echo $provider->getName() . "\n"; } /* getProvider() accepts the name of a supported provider, and returns a ManyDNS\Client object (or NULL if none is found). */ $provider = ManyDNS::getProvider('NoIP'); /* To perform a new update of DNS addressing, just call the updateNow() function on the preferred client. The $ip parameter is optional: most providers accepts the current public IP as default, if not the package tries to retrieve the current public IP of the instance. */ try { $provider->updateNow($username, $password, $hostname, $ip); } catch (FailedUpdateException $e) { /* In case of error, FailedUpdateException provides both a human message and an error code defined as: ManyDNS::ERROR_INVALID_AUTH ManyDNS::ERROR_INVALID_HOST ManyDNS::ERROR_UNKNOWN */ echo $e->getMessage() . "\n"; echo $e->getCode() . "\n"; }
特殊行为
DuckDNS认证基于单个令牌,用于更新请求时替换密码。
$provider = ManyDNS::getProvider('DuckDNS');
$provider->updateNow(null, $token, $hostname, $ip);