這個IP庫實測還是比較准確的,免費版的可以具體到國內城市,國外只能到國家名稱,免費版的自己定期更新Ip數據庫即可。
以下為C#調用代碼
class Program
{
static void Main(string[] args) { try { //傳入要查詢的ip 和17monipdb.datx 下載的ip庫所在位置 string address = IPAddress.FindIPAddress("1.198.219.205", @"D:\開發資料\資料\Code\IP地址獲取\IPAddress\IPAddress\bin\Debug"); 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