IP2Region为老的组件,数据库为.db格式的,安装好依赖包,输入如下代码即可
com.c_Ip = HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
using (DbSearcher search = new DbSearcher(_hostingEnvironment.WebRootPath + @"/ip2region.db"))
{
IP2Region.Models.DataBlock ipModel = search.MemorySearch(com.c_Ip);
com.c_City = ipModel.Region;//中国|0|浙江省|杭州市|电信
}
Searcher searcher = new Searcher(CachePolicy.File, _hostingEnvironment.WebRootPath + @"/ip2region.xdb");
searcher.Search("47.100.83.177");
- 本文标题: NETCORE之IP2Region获取IP及城市地区
- 文章分类:【.NET/Web】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.