修改解析IP区域位置的库 以及异地登录判断
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using IRaCIS.Core.Domain.Models;
|
||||
using MaxMind.GeoIP2;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IRaCIS.Core.Application.Helper
|
||||
{
|
||||
public static class IPCityHelper
|
||||
{
|
||||
|
||||
public static string GetCityResponse(string ip)
|
||||
{
|
||||
var path = Path.Combine(AppContext.BaseDirectory, StaticData.Folder.Resources, "GeoLite2-City.mmdb");
|
||||
|
||||
try
|
||||
{
|
||||
using (var reader = new DatabaseReader(path))
|
||||
{
|
||||
|
||||
var city = reader.City(ip);
|
||||
|
||||
//Console.WriteLine(city.Country.IsoCode); // 'US' 'CN'
|
||||
//Console.WriteLine(city.Country.Name); // 'United States' 'China'
|
||||
////Console.WriteLine(city.Country.Names["zh-CN"]); // '美国'
|
||||
//Console.WriteLine(city.MostSpecificSubdivision.Name); // 'Minnesota' 'Hubei'
|
||||
//Console.WriteLine(city.City.Name); // 'Minneapolis' 'WUHan'
|
||||
|
||||
return $"{city.Country.Name} | {city.MostSpecificSubdivision.Name} | {city.City.Name}";
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
return $"UN | UN | {ip}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user