Information Gathering with IPSTACK a Free Geolocalization API
This is another simple script with python 3.8 for information gathering. I used the free version of the IPSTACK API to make this script. I did not provide an API key for this tutorial. If you want to try it yourself, you need to sign up on their website. It is completely free, but you are limited to only ten thousand requests a month.
Also, I added another simple feature at the end of the script. It will use the longitude and latitude variables from the script to open Google Map on your default web browser. Even though, Google Map has their own API. I won’t use it for now, because the script runs on the command line, or terminal for the Linux users.
To run this script, you will need a valid IP Address and your free API key.
CLICK HERE TO SIGN UP FOR A KEY
Name of the script: whatever_you_like.py
import requests, json, time, os
import webbrowser
#https://ipstack.com/quickstart
url = "http://api.ipstack.com/"
ip = "" # IP Address
middleV = "?access_key="
apiKey = "" #Insert your API key you get from https://ipstack.com/signup/free
cUrl = url + ip + middleV + apiKey
#Start the request
session = requests.session()
ipstack = session.get(cUrl).json()
dictx = {
"ip":ipstack['ip'],
"type":ipstack['type'],
"continent_code":ipstack['continent_code'],
"continent_name":ipstack['continent_name'],
"country_code":ipstack['country_code'],
"country_name":ipstack['country_name'],
"region_code":ipstack['region_code'],
"region_name":ipstack['region_name'],
"city":ipstack['city'],
"zip":ipstack['zip'],
"latitude":ipstack['latitude'],
"longitude":ipstack['longitude']
}
# for loop to print the dictionary data or variable
for x, y in dictx.items():
print(x,":", y)
gMap = "https://www.google.com/maps/search/?api=1&query=" + str(ipstack['latitude']) + "," + str(ipstack['longitude'])
webbrowser.open(gMap) #open google map on your default webbrowser