Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- 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
- Support [](https://free.freeipapi.com/api/json) IPv6 API

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- Support [freeipapi.com](https://freeipapi.com/api/json/) IPv6 API

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in c19099b

### 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`, `myip.la`]
ℹ️ `ipv6-api` valid choices: [`auto-safe`, `auto`, `ip.sb`, `ident.me`, `tnedi.me`, `ipleak.net`, `my-ip.io`, `ifconfig.co`, `reallyfreegeoip.org`, `myip.la`, `freeipapi.com`]

ℹ️ 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 @@ -262,6 +262,35 @@ def _myip_la_ipv6(geo: bool=False, timeout: Union[float, Tuple[float, float]]
return {"status": False, "error": str(e)}


def _freeipapi_com_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 freeipapi.com.

:param geo: geolocation flag
:param timeout: timeout value for API
"""
try:
data = _get_json_force_ip(url="https://free.freeipapi.com/api/json", timeout=timeout, version="ipv6")
result = {"status": True, "data": {"ip": data["ipAddress"], "api": "freeipapi.com"}}
tzs = data.get("timeZones", [None])
if geo:
geo_data = {
"city": data.get("cityName"),
"region": data.get("regionName"),
"country": data.get("countryName"),
"country_code": data.get("countryCode"),
"latitude": data.get("latitude"),
"longitude": data.get("longitude"),
"organization": data.get("asnOrganization"),
"timezone": tzs[0]
}
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 @@ -302,6 +331,11 @@ def _myip_la_ipv6(geo: bool=False, timeout: Union[float, Tuple[float, float]]
"thread_safe": False,
"geo": True,
"function": _myip_la_ipv6
},
IPv6API.FREEIPAPI_COM: {
"thread_safe": False,
"geo": True,
"function": _freeipapi_com_ipv6
}
}

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


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 @@ -68,6 +68,14 @@ def test_public_ipv6_myip_la_success():
assert result["data"]["api"] == "myip.la"


def test_public_freeipapi_com_success():
result = get_public_ipv6(api=IPv6API.FREEIPAPI_COM, 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"] == "freeipapi.com"


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
Loading