Track Location of an IP Address using Python

Python, Scripts - November 7, 2022 - 2 min read

Overview

How IP addresses work?

You are assigned an IP address when you connect to the internet via your Internet service provider (ISP). Your IP address is similar to your postal address, but it is unique to your computer on the Internet. The IP address is used to direct Internet traffic to your computer. To be clear, it does not reveal your exact location. If someone obtains your IP address, they can learn some information about your Internet service, such as which provider you use to connect to the Internet, but they cannot locate you, your home, or your office.

Should I worry about someone finding me with my IP address?

In short, you don't have to be concerned about being tracked down by your IP address. Your IP address does not contain enough information to pinpoint your exact physical location to anyone who attempts to trace your IP address and locate you. A person may be able to locate the city or general area you're in in some cases. However, they are unable to obtain your physical address; while your IP address is linked to a geographical location, it is insufficient to locate you. Anyone who follows your IP address can only reach your Internet service provider.

How to hide your IP address?

If you are still concerned about the information revealed by your IP address, you have options. There are several advantages to masking your IP address. It secures your connection, which is especially useful when using public WiFi. It enables you to avoid filters and content blocks. Most importantly, it increases your online security.

When browsing the web, consider using a VPN or proxy to hide your IP address. Both improve your privacy by masking your IP address and safeguarding your online activity.

Python program for extracting information from IP addresses

Prepare your tools

We'll be using the requests library in Python. You can install this library using the pip command like this:

pip install requests

Python Code

from requests import get
from json import loads

def getDetails(ipAddress):
    r = get('http://ip-api.com/json/{0}'.format(ipAddress))
    data = loads(r.content)
    return data

ipAddress = input("Enter ip address to track: ")
data = getDetails(ipAddress)
for key, value in data.items():
    print(key, ":", value)

Output Screenshot