Extracting geolocation information
One way to obtain geolocation from an IP address or a domain is by using a service that provides location data such as the country, latitude, and longitude. Among the services that provide this information in an easy way, hackertarget.com
is a popular service with quality location data (https://hackertarget.com/geoip-ip-location-lookup). This service also provides a REST API for obtaining geolocation from an IP address using the https://api.hackertarget.com/geoip/?q=8.8.8.8 endpoint:
IP Address: 8.8.8.8
Country: United States
State: California
City: Los Angeles
Latitude: 34.0544
Longitude: -118.2441
We can use similar services to get geolocation, such as https://ip-api.com. This service provides an endpoint to get geolocation by IP address: http://ip-api.com/json/8.8.8.8. In the following script, we are using this service and the requests
module to obtain a JSON response with geolocation information. You can find the following code in the...