@@ -379,6 +379,34 @@ def _tnedi_me_ipv4(geo: bool=False, timeout: Union[float, Tuple[float, float]]
379
379
return {"status" : False , "error" : str (e )}
380
380
381
381
382
+ def _freeipapi_com_ipv4 (geo : bool = False , timeout : Union [float , Tuple [float , float ]]= 5
383
+ ) -> Dict [str , Union [bool , Dict [str , Union [str , float ]], str ]]:
384
+ """
385
+ Get public IP and geolocation using freeipapi.com.
386
+
387
+ :param geo: geolocation flag
388
+ :param timeout: timeout value for API
389
+ """
390
+ try :
391
+ data = _get_json_ipv4_forced (url = "https://freeipapi.com/api/json" , timeout = timeout )
392
+ result = {"status" : True , "data" : {"ip" : data ["ipAddress" ], "api" : "freeipapi.com" }}
393
+ if geo :
394
+ geo_data = {
395
+ "city" : data .get ("cityName" ),
396
+ "region" : data .get ("regionName" ),
397
+ "country" : data .get ("countryName" ),
398
+ "country_code" : data .get ("countryCode" ),
399
+ "latitude" : data .get ("latitude" ),
400
+ "longitude" : data .get ("longitude" ),
401
+ "organization" : None ,
402
+ "timezone" : data .get ("timeZone" )
403
+ }
404
+ result ["data" ].update (geo_data )
405
+ return result
406
+ except Exception as e :
407
+ return {"status" : False , "error" : str (e )}
408
+
409
+
382
410
IPV4_API_MAP = {
383
411
IPv4API .IFCONFIG_CO : {
384
412
"thread_safe" : False ,
@@ -430,6 +458,11 @@ def _tnedi_me_ipv4(geo: bool=False, timeout: Union[float, Tuple[float, float]]
430
458
"geo" : True ,
431
459
"function" : _reallyfreegeoip_org_ipv4
432
460
},
461
+ IPv4API .FREEIPAPI_COM : {
462
+ "thread_safe" : False ,
463
+ "geo" : True ,
464
+ "function" : _freeipapi_com_ipv4 ,
465
+ }
433
466
}
434
467
435
468
0 commit comments