This article is a mirror article of machine translation, please click here to jump to the original article.

View: 99046|Reply: 12

[Console Program] .net/c# uses the GeoLite2 IP database to get the address

[Copy link]
Posted on 5/20/2018 2:22:35 PM | | | |
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, pleaseReply






Previous:Borrow the right to silently log in to DISCUZ without an authentication number
Next:Share a single APP promotional page code source, adaptive, very beautiful and generous!
 Landlord| Posted on 11/22/2024 11:17:07 PM |
GeoLite2 Free Geolocation Data (Registration Required, Not Tested):The hyperlink login is visible.
GitHub Automatic Update Release:The hyperlink login is visible.

 Landlord| Posted on 5/10/2023 7:52:12 PM |
[Actual combat]. NET/C# offline IP address (home) locator library
https://www.itsvse.com/thread-10585-1-1.html
Posted on 8/6/2018 6:03:30 PM |
Very good very good very good very good very good
Posted on 5/21/2018 6:05:54 PM |
Thanks for sharing.
Posted on 7/1/2018 10:02:12 AM |
Prompt:Authors are banned or removed content is automatically blocked
Posted on 7/25/2018 9:51:57 AM |
Very good dongdong
Posted on 8/19/2018 9:48:08 AM |
I learned, thank you for sharing, thank you for sharing,
Posted on 5/23/2019 1:41:26 PM |
+1+1+1+1+1+1+1+1+1+1
Posted on 4/19/2021 5:18:59 PM |

Thanks for sharing.
Posted on 7/5/2021 8:21:49 PM |
Thanks for sharing.
Posted on 4/6/2022 5:37:44 PM |
It's really good
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com