dynamicdns 0.1.0rc0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dynamicdns/__init__.py +14 -0
- dynamicdns/const.py +15 -0
- dynamicdns/providers.py +107 -0
- dynamicdns/updater.py +37 -0
- dynamicdns-0.1.0rc0.dist-info/METADATA +48 -0
- dynamicdns-0.1.0rc0.dist-info/RECORD +8 -0
- dynamicdns-0.1.0rc0.dist-info/WHEEL +4 -0
- dynamicdns-0.1.0rc0.dist-info/licenses/LICENSE.txt +9 -0
dynamicdns/__init__.py
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# SPDX-FileCopyrightText: 2025-present tr4nt0r <4445816+tr4nt0r@users.noreply.github.com>
|
2
|
+
#
|
3
|
+
# SPDX-License-Identifier: MIT
|
4
|
+
|
5
|
+
from .providers import Provider, ProviderConf, providers
|
6
|
+
from .updater import Updater
|
7
|
+
|
8
|
+
__version__ = "0.1.0rc0"
|
9
|
+
__all__ = [
|
10
|
+
"providers",
|
11
|
+
"Provider",
|
12
|
+
"ProviderConf",
|
13
|
+
"Updater",
|
14
|
+
]
|
dynamicdns/const.py
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
"""Constants."""
|
2
|
+
|
3
|
+
from typing import Final
|
4
|
+
|
5
|
+
CONF_HOSTS: Final = "hosts"
|
6
|
+
CONF_HOST: Final = "host"
|
7
|
+
CONF_TOKEN: Final = "token"
|
8
|
+
CONF_USERNAME: Final = "username"
|
9
|
+
CONF_PASSWORD: Final = "password"
|
10
|
+
CONF_IP_ADDRESS: Final = "ip_address"
|
11
|
+
CONF_IPV6_ADDRESS: Final = "ipv6_address"
|
12
|
+
CONF_VERBOSE: Final = "verbose"
|
13
|
+
CONF_TXT: Final = "txt"
|
14
|
+
CONF_CLEAR: Final = "clear"
|
15
|
+
CONF_DOMAIN: Final = "domain"
|
dynamicdns/providers.py
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
"""List of dynamic DNS providers."""
|
2
|
+
|
3
|
+
from __future__ import annotations
|
4
|
+
|
5
|
+
from dataclasses import dataclass, field
|
6
|
+
from enum import StrEnum
|
7
|
+
from typing import Callable
|
8
|
+
|
9
|
+
import voluptuous as vol
|
10
|
+
from yarl import URL
|
11
|
+
|
12
|
+
from .const import (
|
13
|
+
CONF_DOMAIN,
|
14
|
+
CONF_HOST,
|
15
|
+
CONF_IP_ADDRESS,
|
16
|
+
CONF_IPV6_ADDRESS,
|
17
|
+
CONF_PASSWORD,
|
18
|
+
CONF_TOKEN,
|
19
|
+
CONF_USERNAME,
|
20
|
+
)
|
21
|
+
|
22
|
+
|
23
|
+
class Provider(StrEnum):
|
24
|
+
"""Dynamic DNS providers."""
|
25
|
+
|
26
|
+
DUCKDNS = "duckdns"
|
27
|
+
MYTHICBEASTS_IPV4 = "mythicbeasts_ipv4"
|
28
|
+
ANYDNS = "anydns"
|
29
|
+
FREEDNS = "freedns"
|
30
|
+
FREEDNS_IPV6 = "freedns_ipv6"
|
31
|
+
|
32
|
+
|
33
|
+
@dataclass(frozen=True, kw_only=True)
|
34
|
+
class ProviderConf:
|
35
|
+
"""Dynamic DNS provider config."""
|
36
|
+
|
37
|
+
name: str
|
38
|
+
base_url: str
|
39
|
+
method: str = "GET"
|
40
|
+
params: dict[str, str] = field(default_factory=dict)
|
41
|
+
schema: vol.Schema
|
42
|
+
success_fn: Callable[[str], bool] | None = None
|
43
|
+
|
44
|
+
def render_url(self, data: dict[str, str]) -> URL:
|
45
|
+
"""Render the provider URL with given data and remove unused query parameters."""
|
46
|
+
|
47
|
+
url = URL(self.base_url)
|
48
|
+
url = url.with_path(url.path.format(**data))
|
49
|
+
return url % {k: data[v] for k, v in self.params.items() if v in data}
|
50
|
+
|
51
|
+
|
52
|
+
providers: dict[Provider, ProviderConf] = {
|
53
|
+
Provider.DUCKDNS: ProviderConf(
|
54
|
+
name="Duck DNS",
|
55
|
+
base_url="https://www.duckdns.org/update?verbose=true",
|
56
|
+
params={
|
57
|
+
"domains": CONF_HOST,
|
58
|
+
"token": CONF_TOKEN,
|
59
|
+
"ip": CONF_IP_ADDRESS,
|
60
|
+
"ipv6": CONF_IPV6_ADDRESS,
|
61
|
+
},
|
62
|
+
schema=vol.Schema(
|
63
|
+
{
|
64
|
+
vol.Required(CONF_HOST): str,
|
65
|
+
vol.Required(CONF_TOKEN): vol.All(str, vol.Length(min=36, max=36)),
|
66
|
+
}
|
67
|
+
),
|
68
|
+
success_fn=lambda x: x.startswith("OK"),
|
69
|
+
),
|
70
|
+
Provider.MYTHICBEASTS_IPV4: ProviderConf(
|
71
|
+
name="Mythic Beasts IPv4",
|
72
|
+
base_url="https://ipv4.api.mythic-beasts.com/dns/v2/dynamic/{domain}",
|
73
|
+
method="POST",
|
74
|
+
params={"username": CONF_USERNAME, "password": CONF_PASSWORD},
|
75
|
+
schema=vol.Schema(
|
76
|
+
{
|
77
|
+
vol.Required(CONF_DOMAIN): str,
|
78
|
+
vol.Required(CONF_USERNAME): str,
|
79
|
+
vol.Required(CONF_PASSWORD): str,
|
80
|
+
},
|
81
|
+
),
|
82
|
+
),
|
83
|
+
Provider.ANYDNS: ProviderConf(
|
84
|
+
name="AnyDNS.info",
|
85
|
+
base_url="https://anydns.info/update.php",
|
86
|
+
params={"host": CONF_HOST, "user": CONF_USERNAME, "password": CONF_PASSWORD},
|
87
|
+
schema=vol.Schema(
|
88
|
+
{
|
89
|
+
vol.Required(CONF_HOST): str,
|
90
|
+
vol.Required(CONF_USERNAME): str,
|
91
|
+
vol.Required(CONF_PASSWORD): str,
|
92
|
+
},
|
93
|
+
),
|
94
|
+
),
|
95
|
+
Provider.FREEDNS: ProviderConf(
|
96
|
+
name="FreeDNS IPv4",
|
97
|
+
base_url="https://sync.afraid.org/u/{token}/",
|
98
|
+
schema=vol.Schema({vol.Required(CONF_TOKEN): str}),
|
99
|
+
success_fn=lambda x: x.startswith(("Updated", "No IP change")),
|
100
|
+
),
|
101
|
+
Provider.FREEDNS_IPV6: ProviderConf(
|
102
|
+
name="FreeDNS IPv6",
|
103
|
+
base_url="https://v6.sync.afraid.org/u/{token}",
|
104
|
+
schema=vol.Schema({vol.Required(CONF_TOKEN): str}),
|
105
|
+
success_fn=lambda x: x.startswith(("Updated", "No IP change")),
|
106
|
+
),
|
107
|
+
}
|
dynamicdns/updater.py
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
"""Dynamic DNS updater."""
|
2
|
+
|
3
|
+
from __future__ import annotations
|
4
|
+
|
5
|
+
import logging
|
6
|
+
|
7
|
+
from aiohttp import ClientSession
|
8
|
+
|
9
|
+
from .providers import Provider, providers
|
10
|
+
|
11
|
+
_LOGGER = logging.getLogger(__package__)
|
12
|
+
|
13
|
+
|
14
|
+
class Updater:
|
15
|
+
"""Dynamic DNS updater class."""
|
16
|
+
|
17
|
+
def __init__(
|
18
|
+
self,
|
19
|
+
provider: Provider,
|
20
|
+
data: dict[str, str],
|
21
|
+
session: ClientSession,
|
22
|
+
) -> None:
|
23
|
+
"""Initialize."""
|
24
|
+
|
25
|
+
self.session = session
|
26
|
+
self.method = providers[provider].method
|
27
|
+
self.url = providers[provider].render_url(data)
|
28
|
+
self.success = providers[provider].success_fn
|
29
|
+
|
30
|
+
async def update(self) -> bool:
|
31
|
+
"""Update the dynamic DNS record."""
|
32
|
+
|
33
|
+
async with self.session.request(self.method, self.url) as res:
|
34
|
+
_LOGGER.debug(await res.text())
|
35
|
+
return (
|
36
|
+
self.success(await res.text()) if self.success is not None else res.ok
|
37
|
+
)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: dynamicdns
|
3
|
+
Version: 0.1.0rc0
|
4
|
+
Summary: Collection of Dynamic DNS providers
|
5
|
+
Project-URL: Documentation, https://github.com/tr4nt0r/dynamicdns#readme
|
6
|
+
Project-URL: Issues, https://github.com/tr4nt0r/dynamicdns/issues
|
7
|
+
Project-URL: Source, https://github.com/tr4nt0r/dynamicdns
|
8
|
+
Author-email: tr4nt0r <4445816+tr4nt0r@users.noreply.github.com>
|
9
|
+
License-Expression: MIT
|
10
|
+
License-File: LICENSE.txt
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
12
|
+
Classifier: Programming Language :: Python
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
18
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
19
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
20
|
+
Requires-Python: >=3.8
|
21
|
+
Requires-Dist: aiohttp>=3.12
|
22
|
+
Requires-Dist: voluptuous>=0.15
|
23
|
+
Requires-Dist: yarl>=1.20
|
24
|
+
Description-Content-Type: text/markdown
|
25
|
+
|
26
|
+
# DynamicDNS
|
27
|
+
|
28
|
+
[](https://pypi.org/project/dynamicdns)
|
29
|
+
[](https://pypi.org/project/dynamicdns)
|
30
|
+
|
31
|
+
-----
|
32
|
+
|
33
|
+
## Table of Contents
|
34
|
+
|
35
|
+
- [DynamicDNS](#dynamicdns)
|
36
|
+
- [Table of Contents](#table-of-contents)
|
37
|
+
- [Installation](#installation)
|
38
|
+
- [License](#license)
|
39
|
+
|
40
|
+
## Installation
|
41
|
+
|
42
|
+
```console
|
43
|
+
pip install dynamicdns
|
44
|
+
```
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
`dynamicdns` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
@@ -0,0 +1,8 @@
|
|
1
|
+
dynamicdns/__init__.py,sha256=PopiNykPYAFKuHkafW_Aw8_OM7jRc8tThVWwN2HolYo,318
|
2
|
+
dynamicdns/const.py,sha256=9aOikA152muIBSyJPoYVa5d8bPwgCogfO28m7pacXXk,388
|
3
|
+
dynamicdns/providers.py,sha256=ZG9O-CAHdyEpfUj5OOyU-X6fjU22NpGQiitERgrT3u4,3193
|
4
|
+
dynamicdns/updater.py,sha256=kEHt-XUXRWYeZwQefdR2ncjD9Kdr0XQTRcjCMxR0NYc,929
|
5
|
+
dynamicdns-0.1.0rc0.dist-info/METADATA,sha256=a9KKhMCt2k79m0uEbComFL_QuquXmlhDlUmeqO3udyw,1626
|
6
|
+
dynamicdns-0.1.0rc0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
7
|
+
dynamicdns-0.1.0rc0.dist-info/licenses/LICENSE.txt,sha256=mRjb1OkwCPh8OBwRrkNZ225tHQ_0eNkVpQjx_vyQx88,1115
|
8
|
+
dynamicdns-0.1.0rc0.dist-info/RECORD,,
|
@@ -0,0 +1,9 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025-present tr4nt0r <4445816+tr4nt0r@users.noreply.github.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|