add require_ipv4 + require_ipv6 config params
This commit is contained in:
parent
62df87f027
commit
90158ca5ad
@ -1,4 +1,3 @@
|
|||||||
import httpx
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import NamedTuple, Optional
|
from typing import NamedTuple, Optional
|
||||||
|
@ -6,7 +6,16 @@ from .plugins import use_plugins
|
|||||||
from typing import Optional
|
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()
|
providers = BaseSourceProvider.registred.values()
|
||||||
ip_addresses = None
|
ip_addresses = None
|
||||||
is_done = False
|
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)
|
done, pending = await asyncio.wait(pending, return_when=asyncio.FIRST_COMPLETED)
|
||||||
for x in done:
|
for x in done:
|
||||||
ip_addresses = x.result()
|
ip_addresses = x.result()
|
||||||
if ip_addresses.ipv4 or ip_addresses.ipv6:
|
if is_valid_addreses(ip_addresses, config):
|
||||||
is_done = True
|
is_done = True
|
||||||
break
|
break
|
||||||
|
ip_addresses = None
|
||||||
|
|
||||||
if pending:
|
if pending:
|
||||||
gather = asyncio.gather(*pending)
|
gather = asyncio.gather(*pending)
|
||||||
@ -96,7 +106,7 @@ async def app(config, ipv4t, ipv6t):
|
|||||||
|
|
||||||
print_debug_info(config)
|
print_debug_info(config)
|
||||||
|
|
||||||
ip_addreses = await get_ip_addresses()
|
ip_addreses = await get_ip_addresses(config)
|
||||||
if ip_addreses is None:
|
if ip_addreses is None:
|
||||||
print("no IP addresses")
|
print("no IP addresses")
|
||||||
return
|
return
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import asyncio
|
|
||||||
import aiofiles
|
import aiofiles
|
||||||
import json
|
import json
|
||||||
import hashlib
|
import hashlib
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import httpx
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from pddnsc.base import BaseSourceProvider
|
from pddnsc.base import BaseSourceProvider
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
debug = true
|
debug = true
|
||||||
|
require_ipv4 = true
|
||||||
|
|
||||||
[sources]
|
[sources]
|
||||||
[sources.ipfy]
|
[sources.ipfy]
|
||||||
provider = "IPIFYSource"
|
provider = "IPIFYSource"
|
||||||
|
[sources.wtf]
|
||||||
|
provider = "WTFIsMyIP"
|
||||||
[sources.fake]
|
[sources.fake]
|
||||||
provider = "FakeSource"
|
provider = "FakeSource"
|
||||||
delay = 10
|
delay = 10
|
||||||
|
Loading…
Reference in New Issue
Block a user