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 @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `ForceIPHTTPAdapter` class
- `_get_json_force_ip` function
- Support [ifconfig.co](https://ifconfig.co/json) IPv6 API
- Support [reallyfreegeoip.org](https://reallyfreegeoip.org/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`]
ℹ️ `ipv6-api` valid choices: [`auto-safe`, `auto`, `ip.sb`, `ident.me`, `tnedi.me`, `ipleak.net`, `my-ip.io`, `ifconfig.co`, `reallyfreegeoip.org`]

ℹ️ The default value: `auto-safe`

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


def _reallyfreegeoip_org_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 reallyfreegeoip.org.

:param geo: geolocation flag
:param timeout: timeout value for API
"""
try:
data = _get_json_force_ip(url="https://reallyfreegeoip.org/json/", timeout=timeout, version="ipv6")
result = {"status": True, "data": {"ip": data["ip"], "api": "reallyfreegeoip.org"}}
if geo:
geo_data = {
"city": data.get("city"),
"region": data.get("region_name"),
"country": data.get("country_name"),
"country_code": data.get("country_code"),
"latitude": data.get("latitude"),
"longitude": data.get("longitude"),
"organization": None, # does not provide organization
"timezone": data.get("time_zone")
}
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 @@ -236,6 +264,11 @@ def _ifconfig_co_ipv6(geo: bool=False, timeout: Union[float, Tuple[float, float]
"geo": True,
"function": _ifconfig_co_ipv6
},
IPv6API.REALLYFREEGEOIP_ORG: {
"thread_safe": False,
"geo": True,
"function": _reallyfreegeoip_org_ipv6
},
}


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


PARAMETERS_NAME_MAP = {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ipv4_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_public_ipv4_tnedi_me_success():
assert result["data"]["api"] == "tnedi.me"


def test_public_ipv4__reallyfreegeoip_org_success():
def test_public_ipv4_reallyfreegeoip_org_success():
result = get_public_ipv4(api=IPv4API.REALLYFREEGEOIP_ORG, geo=True, timeout=40, max_retries=4, retry_delay=90)
assert result["status"]
assert is_ipv4(result["data"]["ip"])
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 @@ -52,6 +52,14 @@ def test_public_ipv6_ifconfig_co_success():
assert result["data"]["api"] == "ifconfig.co"


def test_public_ipv6_reallyfreegeoip_org_success():
result = get_public_ipv6(api=IPv6API.REALLYFREEGEOIP_ORG, 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"] == "reallyfreegeoip.org"


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