How to Track location by IP address | Python

  • Post author:
  • Post comments:0 Comments
  • Reading time:15 mins read

In this article, we are going to show you a new Python project that how you can track someone’s location using Python.

How to Track Location by IP Address using Python

In the digital age, information is more accessible than ever before. Among the various data points, one of the most valuable is the location of a device based on its IP address. With Python, you can develop a location-tracking tool that can provide insights into the physical location of a user or device. In this article, we will explore how to track location by IP address using Python

Writing the Python Code

Now, let’s write a Python script that tracks someone’s location using IP address

import requests
import json

ip = ''  # replace with the IP address you want to look up

response = requests.get(f'{ip}/json/')
result = response.json()

# Save the IP data to a JSON file
with open('ip_data.json', 'w') as file:
    json.dump(result, file)

print('IP data saved to ip_data.json')

Running the Script

To use this script, follow these steps:

  1. Save the script to a Python file, for example,
  2. Open your terminal or command prompt.
  3. Navigate to the directory where you saved the script.
  4. Run the script using the command:
  1. Enter the IP address you want to track when prompted.

The script will make an API request, retrieve the geolocation data, and display it in your terminal.


Tracking location by IP address is a powerful capability that can be used for various purposes, from website analytics to security monitoring. With Python and the ipapi, you can easily access location data based on IP addresses. However, always ensure that you comply with legal and ethical considerations when using this information, respecting the privacy of users and following data protection regulations.

Latest posts by Publisher (see all)


Publisher @ideasorblogs

Leave a Reply