Soft PYTHON | Узнать информацию по IP
Всех приветствую. В данном статье, я покажу, как можно узнать информацию по ip адресам с помощью python. Конечно это, не "суперский код", но он интересен. Пример, мы хотим узнать о ip города Москвы, это очень легко сделать, для этого создайте файл на python
Если у вас не установлен библиотека requests — pip install requests
Как видите, мы создали категории: Location, Country и т.д, тоесть страна, регион, локация, сити и айпишник сам.
Теперь, откройте терминал и запускаем
За одно и еще видео <3
Простите, за такое плохое качество в видео.
Тоесть, мы ввели Ip Москвы 109.252.255.162 , и он вывел нам небольшую информацию.
Надеюсь, статья была полезна для вас, если возникнут вопросы я вам их отвечу.
Всего доброго.
How to geolocate an IP address in Python

Geolocating an IP address is a convenient way to identify a user's real-world location. This information can be used in a variety of ways to improve user experience, provide custom marketing, and restrict content by region. You can get a lot of data just from an IP address, like the user's currency, timezone, whether they're using a proxy or VPN, and general location. You can also use a timezone API to get more insight into specific data points.
With this information, you can improve user experience by tailoring your platform to the user. For example, you can display prices in the local currency, show dates and times in the appropriate regional format, and provide the location of the closest physical story. A common reason to do this geolocation is to show the European Users a cookie banner as required by GDPR and other regulations.
This blog post covers how to geolocate a user's IP address using Python.
Don't reinvent the wheel.
Abstract's APIs are production-ready now.
Abstract's suite of API's are built to save you time. You don't need to be an expert in email validation, IP geolocation, etc. Just focus on writing code that's actually valuable for your app or business, and we'll handle the rest.
Geolocate an IP address using an IP address database
One way to geolocate an IP address is to use an online geolocation database. One popular option, Geolocation DB, is free-to-use without an API key. This database includes a massive number of IP addresses obtained from Internet service providers. By querying the service, you can get an approximate location for a specified IP address.
For example, we can query Geolocation DB to geolocate the IP address 147.229.2.90 as follows:
For the provided IP address, this call returns the data:
Drawbacks to this approach
Because Geolocation DB is a free-to-use database, it does not provide much transparency toward the accuracy of its data. There also is not a method to easily confirm the validity of the IP locations. As a result, the use of this database introduces an unknown level of inaccuracy to geolocation data.
Additionally, this approach provides minimal information about the IP address and returns data exclusively referring to the estimated location. For example, accessing information like timezone and currency from this data would require querying secondary databases. This database also does not provide any information about whether the user is using a VPN to access the information. Since some people use VPNs to hide their real IP addresses and location, identifying the use of a VPN can be used to eliminate inaccurate location data.
Geolocate an IP address using Abstract's geolocation API
Abstract API offers a free geolocation API that provides detailed information about user IP addresses. It provides information about the user's location including city, state/region, country, and more, as well as information about their timezone, currency, and regional flag. The availability of this information makes it easy to customize your platform without querying external sources. Additionally, this API detects whether the user is connecting to the network via a VPN, making it easier to identify altered location data.
Python IP Geolocation
In this tutorial, we will be using geoip2 to find a geolocation of any IP Address.
geoip2 is a Python package provided by Maxmind. Two different products are offered with the geoip2 package. First is a web service. This is a pay per use product. You will need to sign up for a User ID and license key to use this. Second, there is a free version in which the database will be downloaded and stored locally. The free version is what we’ll be covering here.
For starters, we will need to install the package:
Once installed, we need to download the database from the Maxmind website:

Download and unzip using the terminal:
When unzipped, you will see a folder with a date appended to it (i.e. GeoLite2-City_20180206). Since this database is updated periodically, future downloads will have a different folder name. In this folder, the file we’re interested in is GeoLite2-City.mmdb, which is the database.
In order to read from this database, we’ll need to create a new Python file and import the geoip2 package.
Create the file:
Import the package:
Next, we will create a new reader variable and use that to open the database:
Next, given an IP address, we can get the IP geolocation info.
Now that we have the geolocation contained in the response variable, we can print the data we’re looking for:
Notice that “subdivisions” is what contains the state info.
Maxmind also follows the standards set by International Organization for Standardization (ISO), which is reflected in the iso_code properties. More info regarding country ISO codes can be found here.
Final note: other databases and a web service (mentioned earlier) are provided by Maxmind. The paid alternatives are generally more accurate and updated more frequently.