preface
During development, we need to record the ip and location information about the login person, which can be achieved through the ip2 region!
For example:
- When qq, gitee, etc. log in a different place, they will remind us to log in a different place!
- Software such as takeout requires geographical location. If our gps is turned off, we can also analyze geographical location based on IP
profile
ip2 region -Offline IP address location library with an accuracy rate of 99.9%, 0.0x millisecond queries, ip2region.db database only has a few MB, and provides query binding algorithms such as java,php,c,python,nodejs,golang, and c#, and Binary, B-tree, and memory. Each IP data segment has a fixed format:
- city ID| countries| regional| provinces| city| ISP_
- github 地址:https://github.com/lionsoul2014/ip2region
use
- nuget installation
Install-Package IP2Region
- Download ip2region.db
git clone https://github.com/lionsoul2014/ip2region.git
然后到 data/文件夹下面找到ip2region.db复制到项目resources下
It's very simple to use, only one line of code
static void Main(string[] args)
{
using (var _search = new DbSearcher(Environment.CurrentDirectory + @"\DB\ip2region.db"))
{
Console.WriteLine(_search.MemorySearch("183.129.193.166").Region);
Console.Read();
}
}
summary
The article comes from improvisation. Although I haven't encountered this kind of need in my work yet, it is always beneficial to understand it. Everyone is welcome to leave a message to discuss it!