2

判断 IP 是否为境内,有什么推荐的方案

 1 year ago
source link: https://www.v2ex.com/t/936578
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

判断 IP 是否为境内,有什么推荐的方案

  myqoo · 13 小时 13 分钟前 · 2723 次点击

要考虑两点,第一是网段的准确性 /实时性,第二是判断性能。

简单搜了下公开的数据,发现 github 有个 china_ip_list 的项目:

https://github.com/17mon/china_ip_list/blob/master/china_ip_list.txt

不过实时性好像不是很高(写着季度更新),不知质量如何。是否还有其他更好的推荐?


第二个是判断性能。之前用过 nodejs 自带的 BlockList,虽然用起来很简单,但后来发现性能并不好,看了下源码才知道它居然是逐条匹配的,没有任何算法优化。

之前也有人反馈过这个问题: https://github.com/nodejs/node/issues/46070

看来目前还是得用 C 写一个 node addon 扩展。

此外,这个算法只用于查询,并没有增删改,并且 CIDR 的范围也是 2 的次方数,是否可进一步优化?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK