Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `_get_json_force_ip` function
- Support [ifconfig.co](https://ifconfig.co/json) IPv6 API
- Support [reallyfreegeoip.org](https://reallyfreegeoip.org/json/) IPv6 API
- Support [myip.la](https://api.myip.la/en?json) IPv6 API
### Removed
- `IPv4HTTPAdapter` class
- `_get_json_ipv4_forced` function
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Public IP and Location Info:

#### IPv6 API

ℹ️ `ipv6-api` valid choices: [`auto-safe`, `auto`, `ip.sb`, `ident.me`, `tnedi.me`, `ipleak.net`, `my-ip.io`, `ifconfig.co`, `reallyfreegeoip.org`]
ℹ️ `ipv6-api` valid choices: [`auto-safe`, `auto`, `ip.sb`, `ident.me`, `tnedi.me`, `ipleak.net`, `my-ip.io`, `ifconfig.co`, `reallyfreegeoip.org`, `myip.la`]

ℹ️ The default value: `auto-safe`

Expand Down
34 changes: 34 additions & 0 deletions ipspot/ipv6.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,35 @@ def _reallyfreegeoip_org_ipv6(geo: bool=False, timeout: Union[float, Tuple[float
return {"status": False, "error": str(e)}


def _myip_la_ipv6(geo: bool=False, timeout: Union[float, Tuple[float, float]]
=5) -> Dict[str, Union[bool, Dict[str, Union[str, float]], str]]:
"""
Get public IP and geolocation using myip.la.

:param geo: geolocation flag
:param timeout: timeout value for API
"""
try:
data = _get_json_force_ip(url="https://api.myip.la/en?json", timeout=timeout, version="ipv6")
result = {"status": True, "data": {"ip": data["ip"], "api": "myip.la"}}
if geo:
loc = data.get("location", {})
geo_data = {
Comment thread
sepandhaghighi marked this conversation as resolved.
"city": loc.get("city"),
"region": loc.get("province"),
"country": loc.get("country_name"),
"country_code": loc.get("country_code"),
"latitude": float(loc.get("latitude")) if loc.get("latitude") else None,
"longitude": float(loc.get("longitude")) if loc.get("longitude") else None,
"organization": None,
"timezone": None
}
result["data"].update(geo_data)
return result
except Exception as e:
return {"status": False, "error": str(e)}


IPV6_API_MAP = {
IPv6API.IP_SB: {
"thread_safe": True,
Expand Down Expand Up @@ -269,6 +298,11 @@ def _reallyfreegeoip_org_ipv6(geo: bool=False, timeout: Union[float, Tuple[float
"geo": True,
"function": _reallyfreegeoip_org_ipv6
},
IPv6API.MYIP_LA: {
"thread_safe": False,
"geo": True,
"function": _myip_la_ipv6
}
}


Expand Down
1 change: 1 addition & 0 deletions ipspot/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class IPv6API(Enum):
MY_IP_IO = "my-ip.io"
IFCONFIG_CO = "ifconfig.co"
REALLYFREEGEOIP_ORG = "reallyfreegeoip.org"
MYIP_LA = "myip.la"


PARAMETERS_NAME_MAP = {
Expand Down
8 changes: 8 additions & 0 deletions tests/test_ipv6_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ def test_public_ipv6_reallyfreegeoip_org_success():
assert result["data"]["api"] == "reallyfreegeoip.org"


def test_public_ipv6_myip_la_success():
result = get_public_ipv6(api=IPv6API.MYIP_LA, geo=True, timeout=40, max_retries=4, retry_delay=90)
assert result["status"]
assert is_ipv6(result["data"]["ip"])
assert set(result["data"].keys()) == DATA_ITEMS
assert result["data"]["api"] == "myip.la"


def test_public_ipv6_auto_success():
result = get_public_ipv6(api=IPv6API.AUTO, geo=True, timeout=40, max_retries=4, retry_delay=90)
assert result["status"]
Expand Down