hackl0us / geoip2-cn Goto Github PK
View Code? Open in Web Editor NEW小巧精悍、准确、实用 GeoIP2 数据库
Home Page: https://hackl0us.com
License: GNU General Public License v3.0
小巧精悍、准确、实用 GeoIP2 数据库
Home Page: https://hackl0us.com
License: GNU General Public License v3.0
好项目,明确授权之后应该会更快推广。
我之前用的是https://ftp.apnic.net/stats/apnic/delegated-apnic-latest这上面的结果,当时我就发现了里面好多相邻的ip范围是可以合并在一起的。所以当我看到这个项目时,我也试了下,确实很多ip范围是可以合并到一起的。
这里是项目的文件,有91800
行
下面是我按照代码合并后的结果,只有8401
行,有10倍的压缩效率,我觉得可以在自动化部署里面加上以下逻辑
package main
import (
"bufio"
"math/big"
"net/http"
"net/netip"
"os"
"strconv"
)
func main() {
err := test()
if err != nil {
panic(err)
}
}
func test() error {
u := "https://github.com/Hackl0us/GeoIP2-CN/raw/release/CN-ip-cidr.txt"
req, err := http.NewRequest(http.MethodGet, u, nil)
if err != nil {
return err
}
c := &http.Client{
// Transport: &http.Transport{
// Proxy: func(r *http.Request) (*url.URL, error) {
// return url.Parse("http://127.0.0.1:1080")
// },
// },
}
resp, err := c.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
var (
cidr, ipv4Cidr, ipv6Cidr []string
br = bufio.NewScanner(resp.Body)
rangeIp = []*big.Int{{}, {}, big.NewInt(1)}
lastV4 = []*big.Int{{}, {}}
lastV6 = []*big.Int{{}, {}}
fillBuf = make([]byte, 16)
)
for br.Scan() {
ip, err := netip.ParsePrefix(br.Text())
if err != nil {
continue
}
// rangeIp[0] 当前行起始ip地址
rangeIp[0].SetBytes(ip.Addr().AsSlice())
rangeIp[1].Set(rangeIp[0])
last, tmp, ipCidr, setBit := lastV4, fillBuf[:4], &ipv4Cidr, 31
if ip.Addr().Is6() {
last, tmp, ipCidr, setBit = lastV6, fillBuf, &ipv6Cidr, 127
}
for i := setBit - ip.Bits(); i >= 0; i-- {
rangeIp[1].SetBit(rangeIp[1], i, 1)
}
rangeIp[1].Add(rangeIp[1], rangeIp[2])
if last[1].Cmp(rangeIp[0]) == 0 {
// 本行起始ip是上一行结束ip+1,可以组成连续ip范围
last[1].Set(rangeIp[1])
} else {
if last[1].BitLen() > 0 {
cidr = ipRangeToCIDR(cidr[:0], tmp, last[0], last[1].Sub(last[1], rangeIp[2]))
*ipCidr = append(*ipCidr, cidr...) // 根据ip起止范围计算CIDR表达式
}
last[0].Set(rangeIp[0])
last[1].Set(rangeIp[1])
}
}
err = br.Err()
if err != nil {
return err
}
if lastV4[1].BitLen() > 0 {
cidr = ipRangeToCIDR(cidr[:0], fillBuf[:4], lastV4[0], lastV4[1].Sub(lastV4[1], rangeIp[2]))
ipv4Cidr = append(ipv4Cidr, cidr...)
}
if lastV6[1].BitLen() > 0 {
cidr = ipRangeToCIDR(cidr[:0], fillBuf, lastV6[0], lastV6[1].Sub(lastV6[1], rangeIp[2]))
ipv6Cidr = append(ipv6Cidr, cidr...)
}
fwCidr := func(name string, cidr []string) error {
fw, err := os.Create(name)
if err != nil {
return err
}
defer fw.Close()
for _, v := range cidr {
fw.WriteString(v + "\n")
}
return nil
}
err = fwCidr("ipv4.txt", ipv4Cidr)
if err != nil {
return err
}
err = fwCidr("ipv6.txt", ipv6Cidr)
if err != nil {
return err
}
return nil
}
func ipRangeToCIDR(cidr []string, buf []byte, ipsInt, ipeInt *big.Int) []string {
var (
tmpInt = new(big.Int)
mask = new(big.Int)
one = big.NewInt(1)
bits uint
maxBit = uint(len(buf) * 8)
)
for {
bits = 1
mask.SetUint64(1)
for bits < maxBit {
if (tmpInt.Or(ipsInt, mask).Cmp(ipeInt) > 0) ||
(tmpInt.Lsh(tmpInt.Rsh(ipsInt, bits), bits).Cmp(ipsInt) != 0) {
bits--
mask.Rsh(mask, 1)
break
}
bits++
mask.Add(mask.Lsh(mask, 1), one)
}
addr, _ := netip.AddrFromSlice(ipsInt.FillBytes(buf))
cidr = append(cidr, addr.String()+"/"+strconv.FormatUint(uint64(maxBit-bits), 10))
if tmpInt.Or(ipsInt, mask); tmpInt.Cmp(ipeInt) >= 0 {
break
}
ipsInt.Add(tmpInt, one)
}
return cidr
}
由于 Clash 的 Country.mmdb 并不能实现自动更新,只能手动替换;而geoip-cn.txt 又不被大部分软件直接接受,因此能否烦请作者同时提供以下格式的内容?
在此先谢过先!
Clash Rule-Provider 文档: https://lancellc.gitbook.io/clash/clash-config-file/rule-provider#example-of-a-rule-provider-file
样例文件:https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/Providers/ChinaIp.yaml
使用方法:
rule-providers:
ChinaIP:
type: http
behavior: ipcidr
path: ./profiles/rule-providers/ChinaIp.yaml
url: https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/Providers/ChinaIp.yaml #由于Clash不支持通过代理更新,需要做镜像/CDN
interval: 86400
rules:
- RULE-SET,ChinaIP,DIRECT
样例文件:https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/ChinaIp.list
使用方法:
[filter_remote]
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/ChinaIp.list, tag=国内 IP 段, force-policy=DIRECT, update-interval=86400, opt-parser=true, enabled=true
样例文件:https://raw.githubusercontent.com/DivineEngine/Profiles/master/Surge/Ruleset/Extra/ChinaIP.list
使用方法:
[Rule]
RULE-SET,https://raw.githubusercontent.com/DivineEngine/Profiles/master/Surge/Ruleset/Extra/ChinaIP.list,DIRECT
酸酸乳+的订阅列表貌似支持的是html格式的。直接订阅txt无法生效。
北邮人网站 byr.pt 没有被识别成国内网站,最后走了“漏网之鱼”规则
MaxMind的数据库里面byr.pt是放在国内网站里的,可以走direct规则
ipip.net包含6010条 纯真包含4730条 怎么一合并就成了490000条了?
如果直接用在QuantumlutX里,手机能撑得住吗?
提供一个为Shadowrocket更新country.mmdb文件的快捷指令,可以按需修改。
https://www.icloud.com/shortcuts/facb97b6bae04c53962bfdd2a0b91146
我看到使用方式中第一条写到:禁用与 **大陆 IP 地址段 直连策略 相关的规则或规则集
意思是不是说像是https://github.com/DivineEngine/Profiles/blob/master/Quantumult/Filter/Extra/ChinaIP.list
和https://github.com/DivineEngine/Profiles/blob/master/Quantumult/Filter/China.list
都不用订阅了呢?
wallet.95516.com
foundation.95516.com
ads.95516.com
open.95516.com
其他的95516.com的网址是可以正常识别为direct规则的
README中说
Clash 及其衍生工具(如 Clash X, Clash for Windows, Clash for Android, OpenClash 等)的用户直接通过上面链接下载 Country.mmdb 并替换掉 Clash 配置文件夹下的同名文件即可。
事实上,clash for android 并不支持自定义,参考:
https://github.com/Kr328/ClashForAndroid/issues/749
https://github.com/Kr328/ClashForAndroid/issues/411#issuecomment-640780469
看了下项目好像不支持iPv6,可不可以添加下对iPv6的支持
wps连接会被识别为others
使用clash作为抗污染DNS服务器时可以基于geoip对查询结果进行过滤,只有IP地址属于CN才返回默认结果,否则返回fallback结果。
但使用本项目的数据库之后fallback会失效,不管查询什么内容都只返回可能被污染的默认结果。
个人猜测是因为clash对IP查询失败之后就继续采用默认结果造成的。不知道能不能增加一个兜底IP结果,将非CN的IP结果返回一个不存在的国家码,从而触发clash的fallback
如题,用于判断下载是否成功
高德地图走代理望添加修复
README中提到
ClashX 和 ClashX Pro
工具开发者 @yicheng 表示后续会考虑支持自定义 GeoIP 库,目前需要使用手动替换的方式来使用项目中提供的数据库。
配置方式:点击状态栏的 ClashX 图标,选择「配置」> 「选择打开本地配置文件夹」,用本项目提供的 Country.mmdb 数据库替换弹出窗口中的同名文件 > 重新启动工具
⚠️ 请勿使用 「配置」> 「实验性功能」> 「更新 IP 数据库」这一功能,否则 IP 数据库会被还原回 MaxMind 的数据库。
该问题在ClashX (Pro)后续Releases中似乎已经修复 commit(https://github.com/yichengchen/clashX/commit/16167b15d2b871b90df293af0871ebf38ff3fc1e)
103.235.46.140:80
114.24.27.200为国内qq空间的ip
等一个
用Kr328 适用于ClashForAndroid 的GEOIP的模版
做了套GeoIP2-CN
https://github.com/ccg2018/ClashForAndroid-Geoip/tree/GeoIP2-CN
生成个jks 就可以打包release了
202.165.96.0/21
202.165.104.0/22
202.165.110.0/23
所包含的ip为海外ip
null
如题
腾讯云IP段,111.231.180.0/23
参考如下,是否可以一并全部补充
https://github.com/LM-Firefly/Rules/blob/master/CCC-CN.list
目前服务器防火墙使用iptables 里面的geoip模块
希望楼主增加对geoip的支持,相关文件为CN.iv4
相关文件供参考
/usr/share/xt_geoip/CN.iv4
/usr/lib/xtables-addons/iv4/CN.iv4
脚本
/usr/lib/xtables-addons/xt_geoip_dl
/usr/lib/xtables-addons/xt_geoip_build
APT包文件
xtables-addons-common xtables-addons-dkms
如题,自行替换mmdb文件后,配置文件仍然是GEOIP, CN
这么指定吗?
如果我只写GEOIP也行吧?
电视盒子:Apple TV
软路由:R4S
翻墙插件:SSRP
软件:Miao Project(商店版)
问题:
通过Miao Project观看哔哩哔哩无法播放番剧,显示区域限制。更换为openclash插件后可以正常播放,后台查看到播放时有两个链接在通过代理节点下载流量并没有走直连,分别是******.bilivideo.com和api.bilibili.com. 邮件询问过Miao Project的开发者,对方表示挂上代理后网络情况较复杂,和软件无关,需要调试规则才能解决。
解决方法:
我返回ssrp插件,在访问控制-直连域名中将bilivideo.com和bilibili.com加入直连列表。翻墙模式依旧选择绕过大陆IP模式,此时番剧可正常播放,不再显示区域限制。
分析:
猜测可能是您的大陆IP列表里面没有bilivideo.com和bilibili.com域名导致的Apple TV通过Miao Project看哔哩哔哩走代理。请大佬检查下是否列表名单内缺失域名,感谢。
dataflow.biliapi.com、api.bilibili.com、app.bilibili.com、passport.bilibili.com
RT
第一行是空行会导致ShadowSocksR Plus+ 无法使用 去掉就可以使用了
点击Quantumult X的右下角风车图标,滑到底部—其他设置,继续滑到底部,GeoLite2有一个来源设置,可以填入您的GeoIP2-CN链接
文档直接用转换工具转换会转换不出来,希望添加v2rayN可支持的geoip.dat,谢谢·
看 ReadMe 说明是只包含了 CN 区域的 IP,但是 Apple 的服务也需要放行的话,就不适用了。
https://blog.maxmind.com/2021/09/data-updates-for-apple-icloud-private-relay/
go.sum (gomod)
==============
Total: 3 (UNKNOWN: 2, LOW: 0, MEDIUM: 1, HIGH: 0, CRITICAL: 0)
+------------------+------------------+----------+-------------------+---------------+---------------------------------------+
| LIBRARY | VULNERABILITY ID | SEVERITY | INSTALLED VERSION | FIXED VERSION | TITLE |
+------------------+------------------+----------+-------------------+---------------+---------------------------------------+
| gopkg.in/yaml.v2 | CVE-2019-11254 | MEDIUM | 2.2.2 | 2.2.8 | kubernetes: Denial of |
| | | | | | service in API server via |
| | | | | | crafted YAML payloads by... |
| | | | | | -->avd.aquasec.com/nvd/cve-2019-11254 |
+ +------------------+----------+ +---------------+---------------------------------------+
| | GMS-2019-2 | UNKNOWN | | v2.2.3 | XML Entity Expansion |
+ +------------------+ + +---------------+---------------------------------------+
| | GO-2021-0061 | | | 2.2.3 | Due to unbounded alias |
| | | | | | chasing, a maliciously crafted |
| | | | | | YAML file can cause the... |
+------------------+------------------+----------+-------------------+---------------+---------------------------------------+
如题
接口都免费调用,很适合个人开发者
https://api-ltc1.doc.coding.io/
配置Quantumult X 時,添加了神機規則中的許多lists,但是發現訪問Facebook時無法刷新內容。通過查看Qx的紀錄發現Facebook默認識別為GeoIP CN,嘗試切換了默認的GeoIP和該項目中的GeoIP,但都是訪問過程中都是直連。最後的解決方法是重新添加Facebook單項策略,手動調整為Proxy。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.