use generic provider for ipfy + wtfismyip

This commit is contained in:
Dmitry Belyaev 2024-02-21 10:02:08 +03:00
parent 38923fec9e
commit c0d1d4b38d
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
2 changed files with 12 additions and 32 deletions

View File

@ -1,19 +1,9 @@
import httpx from pddnsc.sources.http import GenericHttpSource
from pddnsc.base import BaseSourceProvider
# https://www.ipify.org/ # https://www.ipify.org/
class IPIFYSource(BaseSourceProvider): class IPIFYSource(GenericHttpSource):
async def fetch_v4(self) -> str: def post_init(self):
async with httpx.AsyncClient(transport=self.ipv4t) as client: super().post_init()
response = await client.get("https://api4.ipify.org") self.url_v4 = "https://api4.ipify.org"
if response.is_success: self.url_v6 = "https://api6.ipify.org"
result = response.text.strip() or None
return result
async def fetch_v6(self) -> str:
async with httpx.AsyncClient(transport=self.ipv6t) as client:
response = await client.get("https://api6.ipify.org")
if response.is_success:
result = response.text.strip() or None
return result

View File

@ -1,20 +1,10 @@
import httpx from pddnsc.sources.http import GenericHttpSource
from pddnsc.base import BaseSourceProvider
# https://wtfismyip.com/ # https://wtfismyip.com/
# https://gitlab.com/wtfismyip/wtfismyip # https://gitlab.com/wtfismyip/wtfismyip
class WTFIsMyIP(BaseSourceProvider): class WTFIsMyIP(GenericHttpSource):
async def fetch_v4(self) -> str: def post_init(self):
async with httpx.AsyncClient(transport=self.ipv4t) as client: super().post_init()
response = await client.get("https://text.ipv4.myip.wtf") self.url_v4 = "https://text.ipv4.myip.wtf"
if response.is_success: self.url_v6 = "https://text.ipv6.myip.wtf"
result = response.text.strip() or None
return result
async def fetch_v6(self) -> str:
async with httpx.AsyncClient(transport=self.ipv6t) as client:
response = await client.get("https://text.ipv6.myip.wtf")
if response.is_success:
result = response.text.strip() or None
return result