Introduction
The GeoLite2 database is a free IP geolocation database that is somewhat comparable to MaxMind's GeoIP2 database, but not as accurate. The GeoLite2 Country vs City database is updated on the first Tuesday of each month. The GeoLite2 ASN database is updated every Tuesday.
When we do development, when users register or log in, we can obtain IP addresses, we want to know which city the IP belongs to, we can analyze users through the city, at this time, the IP database is very important!
Website:https://dev.maxmind.com/zh-hans/geoip/geoip2/geolite2/
use
We first download GeoLite2 City and GeoLite2 Country from the official website, the former includes the city, the latter does not include the city, and can only be obtained through the IP of the belonging country.
How do I call it in C#? Start by creating a .NET 4.5 project and then run the following command with nuget:
This library uses . NETFramework version 4.5 and above. .NET standard 1.4 or above.
After the installation is completed, remember to copy the "GeoLite2-City.mmdb" file to the bin directory of the program!!
Execute the code like this:
The results are as follows:
https://www.itsvse.com by:小slag The input IP address is:47.94.71.45
city {"geoname_id":1808926,"names":{"de":"Hangzhou","en":"Hangzhou","es":"Hangzhou","fr":"Hangzhou","ja":"Hangzhou","pt-BR":"Hangzhou","ru":"Ханчжоу","zh-CN":"Hangzhou"}}
continent {"code":"AS","geoname_id":6255147,"names":{"de":"Asien","en":"Asia","es":"Asia","fr":"Asie","ja":"Asia","pt-BR":"ásia","ru":"Азия","zh-CN":"Asia"}}
country {"geoname_id":1814991,"iso_code":"CN","names":{"de":"China","en":"China","es":"China","fr":"Chine","en":"China","pt-BR":"China","ru":"Китай","zh-CN":"China"}}
locatio{filter}n {"accuracy_radius":50,"latitude":30.2936,"longitude":120.1614,"time_zone":"Asia/Shanghai"}
registered_country {"geoname_id":1814991,"iso_code":"CN","names":{"de":"China","en":"China","es":"China","fr":"Chine","ja":"China","pt-BR":"China","ru":"Китай","zh-CN":" China"}}
subdivisions [{"geoname_id":1784764,"iso_code":"ZJ","names":{"en":"Zhejiang","fr":"Province de Zhejiang","zh-CN":"Zhejiang Province"}}]
Please press any key to continue. . . .
We inquired about 3 IP addresses, one is Baidu's IP address, one is the local Internet IP address, and the other is the IP address of this website. As shown below:
Only the IP query of our site is inaccurate, and the IP database cannot be 100% accurate, because the IP can change every day and be assigned to different cities.
GeoIP2 City accuracy
https://www.maxmind.com/zh/geoip2-city-accuracy-comparison
Finally, attach the source code:
Tourists, if you want to see the hidden content of this post, please Reply
|