这个IP库实测还是比较准确的,免费版的可以具体到国内城市,国外只能到国家名称,免费版的自己定期更新Ip数据库即可。
以下为C#调用代码
class Program
{
static void Main(string[] args)
{
try
{
//传入要查询的ip 和17monipdb.datx 下载的ip库所在位置
string address = IPAddress.FindIPAddress("1.198.219.205", @"D:开发资料资料CodeIP地址获取IPAddressIPAddressinDebug");
Console.WriteLine(address);
}
catch (IOException ioex)
{
Console.WriteLine(ioex.StackTrace);
}
catch (IPv4FormatException ipex)
{
Console.WriteLine(ipex.StackTrace);
}
Console.ReadKey(true);
}
}
public class IPAddress
{
public static string FindIPAddress(string ip,string basePath)
{
string address = "";
if (string.IsNullOrEmpty(ip))
{
return address;
}
try
{
string path = string.Format("{0}\{1}", basePath, "17monipdb.datx");
City city = new City(path);
string[] arr = city.find(ip);
if (arr != null && arr.Length > 0)
{
address = string.Join("-", arr);
}
}
catch (IOException ioex)
{
Console.WriteLine(ioex.StackTrace);
}
catch (IPv4FormatException ipex)
{
Console.WriteLine(ipex.StackTrace);
}
return address.TrimEnd("-".ToCharArray());
}
}
IPIP.net官网在这
戳戳戳
————————————————
版权声明:本文为CSDN博主「皮皮虾大侠」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Asa_Jim/article/details/94394612 是本人CSDN原创
- 23
- 00
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 00
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 00
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12