Skip to content

Commit 7d5a2a7

Browse files
New API: Reallyfreegeoip.org (#78)
* feat : _reallyfreegeoip_org_ipv6 added * fix : tests updated * doc : README.md updated * doc : CHANGELOG.md updated * fix : minor edit in tests
1 parent d19a766 commit 7d5a2a7

6 files changed

Lines changed: 45 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99
- `ForceIPHTTPAdapter` class
1010
- `_get_json_force_ip` function
1111
- Support [ifconfig.co](https://ifconfig.co/json) IPv6 API
12+
- Support [reallyfreegeoip.org](https://reallyfreegeoip.org/json/) IPv6 API
1213
### Removed
1314
- `IPv4HTTPAdapter` class
1415
- `_get_json_ipv4_forced` function

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Public IP and Location Info:
214214

215215
#### IPv6 API
216216

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

219219
ℹ️ The default value: `auto-safe`
220220

ipspot/ipv6.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,34 @@ def _ifconfig_co_ipv6(geo: bool=False, timeout: Union[float, Tuple[float, float]
205205
return {"status": False, "error": str(e)}
206206

207207

208+
def _reallyfreegeoip_org_ipv6(geo: bool=False, timeout: Union[float, Tuple[float, float]]
209+
=5) -> Dict[str, Union[bool, Dict[str, Union[str, float]], str]]:
210+
"""
211+
Get public IP and geolocation using reallyfreegeoip.org.
212+
213+
:param geo: geolocation flag
214+
:param timeout: timeout value for API
215+
"""
216+
try:
217+
data = _get_json_force_ip(url="https://reallyfreegeoip.org/json/", timeout=timeout, version="ipv6")
218+
result = {"status": True, "data": {"ip": data["ip"], "api": "reallyfreegeoip.org"}}
219+
if geo:
220+
geo_data = {
221+
"city": data.get("city"),
222+
"region": data.get("region_name"),
223+
"country": data.get("country_name"),
224+
"country_code": data.get("country_code"),
225+
"latitude": data.get("latitude"),
226+
"longitude": data.get("longitude"),
227+
"organization": None, # does not provide organization
228+
"timezone": data.get("time_zone")
229+
}
230+
result["data"].update(geo_data)
231+
return result
232+
except Exception as e:
233+
return {"status": False, "error": str(e)}
234+
235+
208236
IPV6_API_MAP = {
209237
IPv6API.IP_SB: {
210238
"thread_safe": True,
@@ -236,6 +264,11 @@ def _ifconfig_co_ipv6(geo: bool=False, timeout: Union[float, Tuple[float, float]
236264
"geo": True,
237265
"function": _ifconfig_co_ipv6
238266
},
267+
IPv6API.REALLYFREEGEOIP_ORG: {
268+
"thread_safe": False,
269+
"geo": True,
270+
"function": _reallyfreegeoip_org_ipv6
271+
},
239272
}
240273

241274

ipspot/params.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class IPv6API(Enum):
5151
IPLEAK_NET = "ipleak.net"
5252
MY_IP_IO = "my-ip.io"
5353
IFCONFIG_CO = "ifconfig.co"
54+
REALLYFREEGEOIP_ORG = "reallyfreegeoip.org"
5455

5556

5657
PARAMETERS_NAME_MAP = {

tests/test_ipv4_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def test_public_ipv4_tnedi_me_success():
123123
assert result["data"]["api"] == "tnedi.me"
124124

125125

126-
def test_public_ipv4__reallyfreegeoip_org_success():
126+
def test_public_ipv4_reallyfreegeoip_org_success():
127127
result = get_public_ipv4(api=IPv4API.REALLYFREEGEOIP_ORG, geo=True, timeout=40, max_retries=4, retry_delay=90)
128128
assert result["status"]
129129
assert is_ipv4(result["data"]["ip"])

tests/test_ipv6_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ def test_public_ipv6_ifconfig_co_success():
5252
assert result["data"]["api"] == "ifconfig.co"
5353

5454

55+
def test_public_ipv6_reallyfreegeoip_org_success():
56+
result = get_public_ipv6(api=IPv6API.REALLYFREEGEOIP_ORG, geo=True, timeout=40, max_retries=4, retry_delay=90)
57+
assert result["status"]
58+
assert is_ipv6(result["data"]["ip"])
59+
assert set(result["data"].keys()) == DATA_ITEMS
60+
assert result["data"]["api"] == "reallyfreegeoip.org"
61+
62+
5563
def test_public_ipv6_auto_success():
5664
result = get_public_ipv6(api=IPv6API.AUTO, geo=True, timeout=40, max_retries=4, retry_delay=90)
5765
assert result["status"]

0 commit comments

Comments
 (0)