Compare commits

...

2 Commits

Author SHA1 Message Date
3e9142cd54
add wtfismyip source 2024-02-20 23:49:57 +03:00
8a1ba06c88
refactor ipfy source 2024-02-20 23:49:31 +03:00
2 changed files with 27 additions and 9 deletions

View File

@ -2,20 +2,18 @@ import httpx
from pddnsc.base import BaseSourceProvider from pddnsc.base import BaseSourceProvider
# https://www.ipify.org/
class IPIFYSource(BaseSourceProvider): class IPIFYSource(BaseSourceProvider):
async def fetch_v4(self) -> str: async def fetch_v4(self) -> str:
async with httpx.AsyncClient(transport=self.ipv4t) as client: async with httpx.AsyncClient(transport=self.ipv4t) as client:
response = await client.get("https://api4.ipify.org/?format=json") response = await client.get("https://api4.ipify.org")
if response.status_code == httpx.codes.OK: if response.is_success:
data = response.json() result = response.text.strip() or None
result = None if not isinstance(data, dict) else data.get("ip")
return result return result
async def fetch_v6(self) -> str: async def fetch_v6(self) -> str:
async with httpx.AsyncClient(transport=self.ipv6t) as client: async with httpx.AsyncClient(transport=self.ipv6t) as client:
response = await client.get("https://api6.ipify.org/?format=json") response = await client.get("https://api6.ipify.org")
if response.status_code == httpx.codes.OK: if response.is_success:
data = response.json() result = response.text.strip() or None
result = None if not isinstance(data, dict) else data.get("ip")
return result return result

View File

@ -0,0 +1,20 @@
import httpx
from pddnsc.base import BaseSourceProvider
# https://wtfismyip.com/
# https://gitlab.com/wtfismyip/wtfismyip
class WTFIsMyIP(BaseSourceProvider):
async def fetch_v4(self) -> str:
async with httpx.AsyncClient(transport=self.ipv4t) as client:
response = await client.get("https://text.ipv4.myip.wtf")
if response.is_success:
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