diff --git a/pddnsc/base.py b/pddnsc/base.py index aa9eaaf..9dea4a0 100644 --- a/pddnsc/base.py +++ b/pddnsc/base.py @@ -1,7 +1,8 @@ import httpx import asyncio from abc import ABC, abstractmethod -from typing import NamedTuple +from typing import NamedTuple, Optional +from netaddr import valid_ipv4, valid_ipv6 class IPAddreses(NamedTuple): @@ -154,3 +155,11 @@ class BaseFilterProvider(ABC): @abstractmethod async def check_imp(self, source_provider, addr_v4, addr_v6): ... + + +def filter_ipv4(value: str) -> Optional[str]: + return value and valid_ipv4(value) and value or None + + +def filter_ipv6(value: str) -> Optional[str]: + return value and valid_ipv6(value) and value or None diff --git a/requirements.txt b/requirements.txt index 488197d..7a980da 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ httpx[http2]>=0.26,<1.0 asyncio>=3.4.3,<4 aiofiles>=23,<24 toml>=0.10,<1 +netaddr>=1,<2 \ No newline at end of file