add require_ipv4 + require_ipv6 config params

This commit is contained in:
Dmitry Belyaev 2024-02-21 12:32:04 +03:00
parent 62df87f027
commit 90158ca5ad
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
5 changed files with 16 additions and 6 deletions

View File

@ -1,4 +1,3 @@
import httpx
import asyncio
from abc import ABC, abstractmethod
from typing import NamedTuple, Optional

View File

@ -6,7 +6,16 @@ from .plugins import use_plugins
from typing import Optional
async def get_ip_addresses() -> Optional[IPAddreses]:
def is_valid_addreses(addrs: IPAddreses, config) -> bool:
result = addrs.ipv4 or addrs.ipv6
if config.get("require_ipv4"):
result = result and addrs.ipv4
if config.get("require_ipv6"):
result = result and addrs.ipv6
return result
async def get_ip_addresses(config) -> Optional[IPAddreses]:
providers = BaseSourceProvider.registred.values()
ip_addresses = None
is_done = False
@ -15,9 +24,10 @@ async def get_ip_addresses() -> Optional[IPAddreses]:
done, pending = await asyncio.wait(pending, return_when=asyncio.FIRST_COMPLETED)
for x in done:
ip_addresses = x.result()
if ip_addresses.ipv4 or ip_addresses.ipv6:
if is_valid_addreses(ip_addresses, config):
is_done = True
break
ip_addresses = None
if pending:
gather = asyncio.gather(*pending)
@ -96,7 +106,7 @@ async def app(config, ipv4t, ipv6t):
print_debug_info(config)
ip_addreses = await get_ip_addresses()
ip_addreses = await get_ip_addresses(config)
if ip_addreses is None:
print("no IP addresses")
return

View File

@ -1,4 +1,3 @@
import asyncio
import aiofiles
import json
import hashlib

View File

@ -1,4 +1,3 @@
import httpx
import asyncio
from pddnsc.base import BaseSourceProvider

View File

@ -1,8 +1,11 @@
debug = true
require_ipv4 = true
[sources]
[sources.ipfy]
provider = "IPIFYSource"
[sources.wtf]
provider = "WTFIsMyIP"
[sources.fake]
provider = "FakeSource"
delay = 10