refactor ipfy source
This commit is contained in:
parent
6949baf12e
commit
8a1ba06c88
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user