Get URL Location using ip2geotools in python

This post will show you how to use ip2geotools module to find url locations in Python. ip2geotools is a simple tool for getting geolocation information about a specific IP address from various geolocation databases. This package provides an API for various geolocation databases.

Requirements and Installation of ip2geotools:

To create this you need to have Python and any IDEs that support Python installed on it. If ip2geotools module is not already installed on your system, you can install it using the pip package manager:
				
					pip install ip2geotools
				
			

Code to get url locations in Python:

				
					import socket
from ip2geotools.databases.noncommercial import DbIpCity
# take input url
url = input("Insert the link:")
#gethostbyname() function of socket module returns the IP address of a given host name
ip = socket.gethostbyname(url)
response = DbIpCity.get(ip,api_key='free')
# print ip
print("IP:",ip) 
# print city
print("City:",response.city)
# print Region
print("Region:",response.region)
# print country
print("Country:",response.country)
				
			
Well, we created a simple project to find the url location  using Python’s ip2geotools module. Python is a very powerful language and the things we can create with Python are limitless. It’s about developing an idea and implementing it. I hope you enjoyed reading my blog on hands-on projects like this one. It is the best way to improve your programming skills.

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *