🌚 🌍 🌝 GeoIP 增强版,自由定制多种格式 GeoIP 文件,包括但不限于 V2Ray dat 格式文件 geoip.dat、MaxMind mmdb 格式文件、sing-box SRS 格式文件、mihomo MRS 格式文件、Clash ruleset、Surge ruleset、Nginx allow & deny 规则文件等。Enhanced edition of GeoIP for Nginx, V2Ray, Xray-core, Clash, mihomo, sing-box, Shadowrocket, Quantumult X, Surge, hysteria, Trojan-Go, dae, etc.
6,510
stars
313
commits
Go
primary language
Sep 10, 2026
updated
GeoIP,意为 IP geographic location,即 IP 地址所对应的地理位置信息,例如所属的国家、地区等。GeoIP 数据文件则存储着 IP 地址所对应的地理位置信息。
GeoIP, which stands for IP geographic location, refers to the geographic location information associated with an IP address, such as the country or region. And GeoIP data files store the geographic location information corresponding to IP addresses.
本项目每周四自动生成多种格式 GeoIP 数据文件,同时提供命令行界面(CLI)工具供用户自行定制 GeoIP 数据文件,包括但不限于 V2Ray dat 格式文件 geoip.dat、MaxMind mmdb 格式文件 Country.mmdb(GeoIP2-Country.mmdb、GeoLite2-Country.mmdb)、sing-box SRS 格式文件、mihomo MRS 格式文件、Clash ruleset 规则文件、Surge ruleset 规则文件、Nginx allow list(允许访问列表)和 Nginx deny list(拒绝访问列表)。
This project releases various formats of GeoIP files automatically every Thursday, and provides a command line interface (CLI) tool for users to customize their own GeoIP files, including but not limited to V2Ray dat format file geoip.dat, MaxMind mmdb format file Country.mmdb(GeoIP2-Country.mmdb, GeoLite2-Country.mmdb), sing-box SRS format file, mihomo MRS format file, Clash ruleset file, Surge ruleset file, Nginx allow list and Nginx deny list.
本项目默认使用 MaxMind GeoLite2 Country CSV 数据生成各个国家和地区的 GeoIP 文件。类别有:
geoip:cn(GEOIP,CN):中国大陆(Mainland China)geoip:hk(GEOIP,HK):香港(Hong Kong)geoip:mo(GEOIP,MO):澳门(Macau)geoip:tw(GEOIP,TW):台湾(Taiwan)geoip:us(GEOIP,US):美国(America)geoip:jp(GEOIP,JP):日本(Japan)geoip:kr(GEOIP,KR):韩国(Korea)geoip:sg(GEOIP,SG):新加坡(Singapore)geoip:mm(GEOIP,MM):缅甸(Myanmar)geoip:ir(GEOIP,IR):伊朗(Iran)geoip:ru(GEOIP,RU):俄罗斯(Russia)geoip:by(GEOIP,BY):白俄罗斯(Belarus)geoip:tm(GEOIP,TM):土库曼斯坦(Turkmenistan)geoip:private(GEOIP,PRIVATE):内网 IP 地址、保留 IP 地址等特殊 IP 地址的集合本项目对 MaxMind 官方 GeoIP 数据做了如下修改和新增:
geoip:cloudflare(GEOIP,CLOUDFLARE)geoip:cloudfront(GEOIP,CLOUDFRONT)geoip:facebook(GEOIP,FACEBOOK)geoip:fastly(GEOIP,FASTLY)geoip:google(GEOIP,GOOGLE)geoip:netflix(GEOIP,NETFLIX)geoip:telegram(GEOIP,TELEGRAM)geoip:twitter(GEOIP,TWITTER)geoip:tor(GEOIP,TOR)[!NOTE] 如果无法访问域名
raw.githubusercontent.com,可以使用第二个地址cdn.jsdelivr.net。 如果无法访问域名cdn.jsdelivr.net,可以将其替换为fastly.jsdelivr.net。*.sha256sum 为校验文件。
本项目发布的所有 GeoIP 文件,请查看 release 分支。以下是部分格式 GeoIP 文件的下载地址和使用方法:
需要先下载 .dat 格式文件,并放置在程序目录内。
"routing": {
"rules": [
{
"type": "field",
"outboundTag": "Direct",
"ip": [
"geoip:cn",
"geoip:private",
"ext:cn.dat:cn",
"ext:private.dat:private",
"ext:geoip-only-cn-private.dat:cn",
"ext:geoip-only-cn-private.dat:private"
]
},
{
"type": "field",
"outboundTag": "Proxy",
"ip": [
"geoip:us",
"geoip:jp",
"geoip:facebook",
"geoip:telegram",
"ext:geoip-asn.dat:facebook",
"ext:geoip-asn.dat:telegram"
]
}
]
}
geodata-mode: true
geox-url:
geoip: "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/geoip.dat"
需要先下载 .dat 格式文件,并放置在 hysteria 程序目录内。
direct(geoip:cn)
proxy(geoip:telegram)
proxy(geoip:us)
需要先下载 .dat 格式文件,并放置在 Trojan-Go 程序目录内。
"router": {
"enabled": true,
"bypass": ["geoip:cn"],
"proxy": ["geoip:telegram", "geoip:us"],
"block": ["geoip:jp"],
"default_policy": "proxy",
"geoip": "./geoip.dat"
}
此 dat 格式文件不能用于 Nginx。
所有国家/地区、新增类别的 dat 格式文件,请查看本项目 release 分支下的 dat 目录。
geoip:cn 和 geoip:private):
geoip:cn):
geoip:private):
部分国家/地区类别:
新增类别:
需要先下载 .mmdb 格式文件,命名为 Country.mmdb,并放置在 Clash 程序目录内。
rules:
- GEOIP,PRIVATE,policy,no-resolve
- GEOIP,FACEBOOK,policy
- GEOIP,CN,policy,no-resolve
geodata-mode: false
geox-url:
mmdb: "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/Country.mmdb"
asn: "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/GeoLite2-ASN.mmdb"
需要将下载地址填入到 Shadowrocket 的设置中。
[Rule]
GEOIP,PRIVATE,DIRECT
GEOIP,FACEBOOK,PROXY
GEOIP,CN,DIRECT
需要将下载地址填入到 Quantumult X 的设置中。
[filter_local]
GEOIP,PRIVATE,DIRECT
GEOIP,FACEBOOK,PROXY
GEOIP,CN,DIRECT
需要将下载地址填入到 Surge 的设置中。
[Rule]
GEOIP,PRIVATE,policy,no-resolve
GEOIP,FACEBOOK,policy
GEOIP,CN,policy,no-resolve
1️⃣ 本项目生成的国家/地区类型 mmdb 文件:
适用于 Nginx,需要配合 ngx_http_geoip2_module 模块使用。
本项目生成的 mmdb 格式文件中,国家/地区类别保留了
Continent和Country里的所有字段,新增类别和GEOIP,PRIVATE类别只保留了Country里的iso_code(两位英文字母表示的国家/地区代号)字段。关于 Maxmind 官方GeoIP2-Country.mmdb和GeoLite2-Country.mmdb数据文件的完整字段,请查看代码。
GEOIP,PRIVATE 类别,不包含上述新增类别。建议优先使用):
GEOIP,PRIVATE 类别,以及上述新增类别。但由于 MaxMind mmdb 格式限制,部分国家/地区类别的 IP 地址数据不如上述 Country-without-asn.mmdb 准确):
GEOIP,CN 和 GEOIP,PRIVATE):
2️⃣ MaxMind 官方版国家/地区类型 mmdb 文件:
适用于 Nginx,需要配合 ngx_http_geoip2_module 模块使用。
3️⃣ MaxMind 官方版 ASN 类型 mmdb 文件:
适用于 mihomo、Shadowrocket、Surge。
"route": {
"rules": [
{
"rule_set": "geoip-cn",
"outbound": "direct"
},
{
"rule_set": "geoip-us",
"outbound": "block"
}
],
"rule_set": [
{
"tag": "geoip-cn",
"type": "remote",
"format": "binary",
"url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/srs/cn.srs"
},
{
"tag": "geoip-us",
"type": "remote",
"format": "binary",
"url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/srs/us.srs"
}
]
}
适用于 sing-box。
所有国家/地区、新增类别的 SRS 格式文件,请查看本项目 release 分支下的 srs 目录。
部分国家/地区类别:
新增类别:
rule-providers:
cn-cidr:
type: http
behavior: ipcidr
format: mrs
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/mrs/cn.mrs"
path: ./mrs/geoip/cn.mrs
interval: 86400
google-cidr:
type: http
behavior: ipcidr
format: mrs
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/mrs/google.mrs"
path: ./mrs/geoip/google.mrs
interval: 86400
rules:
- RULE-SET,cn-cidr,DIRECT
- RULE-SET,google-cidr,PROXY,no-resolve
适用于 mihomo。
所有国家/地区、新增类别的 MRS 格式文件,请查看本项目 release 分支下的 mrs 目录。
部分国家/地区类别:
新增类别:
rule-providers:
cn-cidr:
type: http
behavior: ipcidr
format: yaml
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/clash/ipcidr/cn.txt"
path: ./ruleset/ipcidr/cn.yaml
interval: 86400
telegram-cidr:
type: http
behavior: ipcidr
format: yaml
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/clash/ipcidr/telegram.txt"
path: ./ruleset/ipcidr/telegram.yaml
interval: 86400
rules:
- RULE-SET,cn-cidr,DIRECT
- RULE-SET,telegram-cidr,PROXY,no-resolve
适用于 Clash Premium、mihomo。
所有国家/地区、新增类别的 Clash ruleset 格式文件,请查看本项目 release 分支下的 clash 目录。
部分国家/地区类别:
新增类别:
[Rule]
RULE-SET,https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/surge/us.txt,REJECT
RULE-SET,https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/surge/cn.txt,DIRECT
RULE-SET,https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/surge/telegram.txt,PROXY,no-resolve
适用于 Surge。
所有国家/地区、新增类别的 Surge ruleset 格式文件,请查看本项目 release 分支下的 surge 目录。
部分国家/地区类别:
新增类别:
allow 和 deny 格式文件所有国家/地区、新增类别的 Nginx allow 和 deny 格式文件,请查看本项目 release 分支下的 nginx 目录。
所有国家/地区、新增类别的纯文本 txt 格式文件,请查看本项目 release 分支下的 text 目录。
部分国家/地区类别:
新增类别:
[!NOTE] 如果需要使用 MaxMind 官方 GeoLite2 数据文件,需要提前从 MaxMind 下载,或者从本项目 release 分支下载(文件名以
GeoLite2为前缀的文件),并解压缩到名为geolite2的目录。
configuration.md 配置说明文档,修改自己仓库内的配置文件 config.json 和 GitHub Workflow .github/workflows/build.ymlgit clone https://github.com/Loyalsoldier/geoip.gitcd geoipconfiguration.md 配置说明文档,修改配置文件 config.jsongo run ./ convert -c ./config.json本项目配置文件 config.json 有两个概念:input 和 output。input 指数据源(data source)及其输入格式,output 指数据的去向(data destination)及其输出格式。CLI 的作用就是通过读取配置文件中的选项,聚合用户提供的所有数据源,去重,将其转换为目标格式,并输出到文件。
These two concepts in configuration file config.json are notable: input and output. The input is the data source and its input format, whereas the output is the destination of the converted data and its output format. What the CLI does is to aggregate all input format data, then convert them to output format and write them to GeoIP files by using the options in the config file.
关于每种格式所支持的配置选项,查看本项目 configuration.md 配置说明文档。
支持的 input 输入格式:
1.1.1.1 或 1.0.0.0/24)1.1.1.1 或 1.0.0.0/24)192.168.0.0/16 和 127.0.0.0/8)geoip.dat)GeoLite2-Country.mmdb)GeoLite2-ASN-CSV.zip)GeoLite2-Country-CSV.zip)dbip-country-lite.mmdb)country.mmdb)geoip-cn.mrs)geoip-cn.srs)支持的 output 输出格式:
1.0.0.0/24)1.0.0.0/24)geoip.dat)GeoLite2-Country.mmdb)dbip-country-lite.mmdb)country.mmdb)geoip-cn.mrs)geoip-cn.srs)由于 MaxMind、DB-IP、IPInfo 的 mmdb 文件格式的限制,当不同列表的 IP 或 CIDR 数据有交集或重复项时,后写入的列表的 IP 或 CIDR 数据会覆盖(overwrite)之前已写入的列表的数据。譬如,IP 1.1.1.1 同属于列表 AU 和列表 Cloudflare。如果 Cloudflare 在 AU 之后写入,则 IP 1.1.1.1 归属于列表 Cloudflare。
为了确保某些指定的列表、被修改的列表一定囊括属于它的所有 IP 或 CIDR 数据,可在 output 相应输出格式的配置中增加选项 overwriteList,该选项中指定的列表会在最后逐一写入,列表中最后一项优先级最高。若已设置选项 wantedList,则无需设置 overwriteList。wantedList 中指定的列表会在最后逐一写入,列表中最后一项优先级最高。
可通过 go install -v github.com/Loyalsoldier/geoip@latest 直接安装 CLI 工具。
CLI 提供的功能如下:
input 和 output 格式(list)convert)lookup)merge)$ ./geoip
geoip is a convenient tool to merge, convert and lookup IP & CIDR from various formats of geoip data.
Usage:
geoip [command]
Available Commands:
convert Convert geoip data from one format to another by using config file
help Help about any command
list List all available input and output formats
lookup Lookup specified IP or CIDR in specified lists
merge Merge plaintext IP & CIDR from standard input, then print to standard output
Flags:
-h, --help help for geoip
Use "geoip [command] --help" for more information about a command.
input 和 output 格式(list)$ ./geoip list
All available input formats:
- clashRuleSet (Convert ipcidr type of Clash RuleSet to other formats)
- clashRuleSetClassical (Convert classical type of Clash RuleSet to other formats (just processing IP & CIDR lines))
- cutter (Remove data from previous steps)
- dbipCountryMMDB (Convert DB-IP country mmdb database to other formats)
- ipinfoCountryMMDB (Convert IPInfo country mmdb database to other formats)
- json (Convert JSON data to other formats)
- maxmindGeoLite2ASNCSV (Convert MaxMind GeoLite2 ASN CSV data to other formats)
- maxmindGeoLite2CountryCSV (Convert MaxMind GeoLite2 country CSV data to other formats)
- maxmindMMDB (Convert MaxMind mmdb database to other formats)
- mihomoMRS (Convert mihomo MRS data to other formats)
- private (Convert LAN and private network CIDR to other formats)
- singboxSRS (Convert sing-box SRS data to other formats)
- stdin (Accept plaintext IP & CIDR from standard input, separated by newline)
- surgeRuleSet (Convert Surge RuleSet to other formats (just processing IP & CIDR lines))
- test (Convert specific CIDR to other formats (for test only))
- text (Convert plaintext IP & CIDR to other formats)
- v2rayGeoIPDat (Convert V2Ray GeoIP dat to other formats)
All available output formats:
- clashRuleSet (Convert data to ipcidr type of Clash RuleSet)
- clashRuleSetClassical (Convert data to classical type of Clash RuleSet)
- dbipCountryMMDB (Convert data to DB-IP country mmdb database format)
- ipinfoCountryMMDB (Convert data to IPInfo country mmdb database format)
- lookup (Lookup specified IP or CIDR from various formats of data)
- maxmindMMDB (Convert data to MaxMind mmdb database format)
- mihomoMRS (Convert data to mihomo MRS format)
- singboxSRS (Convert data to sing-box SRS format)
- stdout (Convert data to plaintext CIDR format and output to standard output)
- surgeRuleSet (Convert data to Surge RuleSet)
- text (Convert data to plaintext CIDR format)
- v2rayGeoIPDat (Convert data to V2Ray GeoIP dat format)
merge)$ curl -s https://core.telegram.org/resources/cidr.txt | ./geoip merge -t ipv4
91.105.192.0/23
91.108.4.0/22
91.108.8.0/21
91.108.16.0/21
91.108.56.0/22
149.154.160.0/20
185.76.151.0/24
convert)$ ./geoip convert -c config.json
2021/08/29 12:11:35 ✅ [v2rayGeoIPDat] geoip.dat --> output/dat
2021/08/29 12:11:35 ✅ [v2rayGeoIPDat] geoip-only-cn-private.dat --> output/dat
2021/08/29 12:11:35 ✅ [v2rayGeoIPDat] geoip-asn.dat --> output/dat
2021/08/29 12:11:35 ✅ [v2rayGeoIPDat] cn.dat --> output/dat
2021/08/29 12:11:35 ✅ [v2rayGeoIPDat] private.dat --> output/dat
2021/08/29 12:11:39 ✅ [maxmindMMDB] Country.mmdb --> output/maxmind
2021/08/29 12:11:39 ✅ [maxmindMMDB] Country-only-cn-private.mmdb --> output/maxmind
2021/08/29 12:11:39 ✅ [text] netflix.txt --> output/text
2021/08/29 12:11:39 ✅ [text] telegram.txt --> output/text
2021/08/29 12:11:39 ✅ [text] cn.txt --> output/text
2021/08/29 12:11:39 ✅ [text] cloudflare.txt --> output/text
2021/08/29 12:11:39 ✅ [text] cloudfront.txt --> output/text
2021/08/29 12:11:39 ✅ [text] facebook.txt --> output/text
2021/08/29 12:11:39 ✅ [text] fastly.txt --> output/text
2021/08/29 12:11:45 ✅ [singboxSRS] netflix.txt --> output/srs
2021/08/29 12:11:45 ✅ [singboxSRS] telegram.txt --> output/srs
2021/08/29 12:11:45 ✅ [singboxSRS] cn.txt --> output/srs
2021/08/29 12:11:45 ✅ [singboxSRS] cloudflare.txt --> output/srs
2021/08/29 12:11:45 ✅ [singboxSRS] cloudfront.txt --> output/srs
2021/08/29 12:11:45 ✅ [singboxSRS] facebook.txt --> output/srs
2021/08/29 12:11:45 ✅ [singboxSRS] fastly.txt --> output/srs
2021/08/29 12:11:50 ✅ [mihomoMRS] netflix.txt --> output/mrs
2021/08/29 12:11:50 ✅ [mihomoMRS] telegram.txt --> output/mrs
2021/08/29 12:11:50 ✅ [mihomoMRS] cn.txt --> output/mrs
2021/08/29 12:11:50 ✅ [mihomoMRS] cloudflare.txt --> output/mrs
2021/08/29 12:11:50 ✅ [mihomoMRS] cloudfront.txt --> output/mrs
2021/08/29 12:11:50 ✅ [mihomoMRS] facebook.txt --> output/mrs
2021/08/29 12:11:50 ✅ [mihomoMRS] fastly.txt --> output/mrs
lookup)可能的返回结果:
falsefalsetrueau,cloudflare# ================= One-time Mode ================= #
# 从 text 格式的本地文件(只包含一个类别)中查找某个 IP 地址
# lookup IP from local file (with only one list) in text format
$ ./geoip lookup -f text -u ./cn.txt 1.0.1.1
true
# 从 text 格式的本地文件(只包含一个类别)中查找某个 IP 地址
# lookup IP from local file (with only one list) in text format
$ ./geoip lookup -f text -u ./cn.txt 2.2.2.2
false
# 从 text 格式的本地文件(只包含一个类别)中查找某个 CIDR
# lookup CIDR from local file (with only one list) in text format
$ ./geoip lookup -f text -u ./cn.txt 1.0.1.1/24
true
# 从 text 格式的本地文件(只包含一个类别)中查找某个 CIDR
# lookup CIDR from local file (with only one list) in text format
$ ./geoip lookup -f text -u ./cn.txt 1.0.1.1/23
false
# 从 text 格式的远程 URL(只包含一个类别)中查找某个 IP 地址
# lookup IP from remote URL (with only one list) in text format
$ ./geoip lookup -f text -u https://example.com/cn.txt 1.0.1.1
true
# 从 v2rayGeoIPDat 格式的本地文件(只包含一个类别)中查找某个 IP 地址
# lookup IP from local file (with only one list) in v2rayGeoIPDat format
$ ./geoip lookup -f v2rayGeoIPDat -u ./cn.dat 1.0.1.1
true
# 从 v2rayGeoIPDat 格式的本地文件(包含多个类别)中查找某个 IP 地址
# lookup IP from local file (with multiple lists) in v2rayGeoIPDat format
$ ./geoip lookup -f v2rayGeoIPDat -u ./geoip.dat 1.0.1.1
cn
# 从 v2rayGeoIPDat 格式的本地文件(包含多个类别)中查找某个 IP 地址
# lookup IP from local file (with multiple lists) in v2rayGeoIPDat format
$ ./geoip lookup -f v2rayGeoIPDat -u ./geoip.dat 1.0.0.1
au,cloudflare
# 从 v2rayGeoIPDat 格式的远程 URL(包含多个类别)中查找某个 CIDR
# lookup CIDR from remote URL (with multiple lists) in v2rayGeoIPDat format
$ ./geoip lookup -f v2rayGeoIPDat -u https://example.com/geoip.dat 1.0.0.1/24
au,cloudflare
# ================= REPL Mode ================= #
# 从 text 格式的本地文件(只包含一个类别)中查找某个 IP 地址或 CIDR
# lookup IP or CIDR from local file (with only one list) in text format
$ ./geoip lookup -f text -u ./cn.txt
Enter IP or CIDR (type "exit" to quit):
>> 1.0.1.1
true
>> 1.0.1.1/24
true
>> 1.0.1.1/23
false
>> 2.2.2.2
false
>> 2.2.2.2/24
false
>> 300.300.300.300
false
>> 300.300.300.300/24
false
>> exit
# 从 text 格式的远程 URL(只包含一个类别)中查找某个 IP 地址或 CIDR
# lookup IP or CIDR from remote URL (with only one list) in text format
$ ./geoip lookup -f text -u https://example.com/cn.txt
Enter IP or CIDR (type "exit" to quit):
>> 1.0.1.1
true
>> 1.0.1.1/24
true
>> 1.0.1.1/23
false
>> 2.2.2.2
false
>> 2.2.2.2/24
false
>> 300.300.300.300
false
>> 300.300.300.300/24
false
>> exit
# 从 v2rayGeoIPDat 格式的本地文件(只包含一个类别)中查找某个 IP 地址或 CIDR
# lookup IP or CIDR from local file (with only one list) in v2rayGeoIPDat format
$ ./geoip lookup -f v2rayGeoIPDat -u ./cn.dat
Enter IP or CIDR (type "exit" to quit):
>> 1.0.1.1
true
>> 1.0.1.1/24
true
>> 1.0.1.1/23
false
>> 2.2.2.2
false
>> 2.2.2.2/24
false
>> 300.300.300.300
false
>> 300.300.300.300/24
false
>> exit
# 从 v2rayGeoIPDat 格式的远程 URL(包含多个类别)中查找某个 IP 地址或 CIDR
# lookup IP or CIDR from remote URL (with multiple list) in v2rayGeoIPDat format
$ ./geoip lookup -f v2rayGeoIPDat -u https://example.com/geoip.dat
Enter IP or CIDR (type "exit" to quit):
>> 1.0.1.1
cn
>> 1.0.1.1/24
cn
>> 1.0.1.1/23
false
>> 1.0.0.1
au,cloudflare
>> 1.0.0.1/24
au,cloudflare
>> 300.300.300.300
false
>> 300.300.300.300/24
false
>> exit
CC-BY-SA-4.0 and GPL-3.0
This product includes GeoLite2 data created by MaxMind, available from MaxMind.
Go
100.0%
🌚 🌍 🌝 GeoIP 增强版,自由定制多种格式 GeoIP 文件,包括但不限于 V2Ray dat 格式文件 geoip.dat、MaxMind mmdb 格式文件、sing-box SRS 格式文件、mihomo MRS 格式文件、Clash ruleset、Surge ruleset、Nginx allow & deny 规则文件等。Enhanced edition of GeoIP for Nginx, V2Ray, Xray-core, Clash, mihomo, sing-box, Shadowrocket, Quantumult X, Surge, hysteria, Trojan-Go, dae, etc.
6,510
stars
313
commits
Go
primary language
Sep 10, 2026
updated
GeoIP,意为 IP geographic location,即 IP 地址所对应的地理位置信息,例如所属的国家、地区等。GeoIP 数据文件则存储着 IP 地址所对应的地理位置信息。
GeoIP, which stands for IP geographic location, refers to the geographic location information associated with an IP address, such as the country or region. And GeoIP data files store the geographic location information corresponding to IP addresses.
本项目每周四自动生成多种格式 GeoIP 数据文件,同时提供命令行界面(CLI)工具供用户自行定制 GeoIP 数据文件,包括但不限于 V2Ray dat 格式文件 geoip.dat、MaxMind mmdb 格式文件 Country.mmdb(GeoIP2-Country.mmdb、GeoLite2-Country.mmdb)、sing-box SRS 格式文件、mihomo MRS 格式文件、Clash ruleset 规则文件、Surge ruleset 规则文件、Nginx allow list(允许访问列表)和 Nginx deny list(拒绝访问列表)。
This project releases various formats of GeoIP files automatically every Thursday, and provides a command line interface (CLI) tool for users to customize their own GeoIP files, including but not limited to V2Ray dat format file geoip.dat, MaxMind mmdb format file Country.mmdb(GeoIP2-Country.mmdb, GeoLite2-Country.mmdb), sing-box SRS format file, mihomo MRS format file, Clash ruleset file, Surge ruleset file, Nginx allow list and Nginx deny list.
本项目默认使用 MaxMind GeoLite2 Country CSV 数据生成各个国家和地区的 GeoIP 文件。类别有:
geoip:cn(GEOIP,CN):中国大陆(Mainland China)geoip:hk(GEOIP,HK):香港(Hong Kong)geoip:mo(GEOIP,MO):澳门(Macau)geoip:tw(GEOIP,TW):台湾(Taiwan)geoip:us(GEOIP,US):美国(America)geoip:jp(GEOIP,JP):日本(Japan)geoip:kr(GEOIP,KR):韩国(Korea)geoip:sg(GEOIP,SG):新加坡(Singapore)geoip:mm(GEOIP,MM):缅甸(Myanmar)geoip:ir(GEOIP,IR):伊朗(Iran)geoip:ru(GEOIP,RU):俄罗斯(Russia)geoip:by(GEOIP,BY):白俄罗斯(Belarus)geoip:tm(GEOIP,TM):土库曼斯坦(Turkmenistan)geoip:private(GEOIP,PRIVATE):内网 IP 地址、保留 IP 地址等特殊 IP 地址的集合本项目对 MaxMind 官方 GeoIP 数据做了如下修改和新增:
geoip:cloudflare(GEOIP,CLOUDFLARE)geoip:cloudfront(GEOIP,CLOUDFRONT)geoip:facebook(GEOIP,FACEBOOK)geoip:fastly(GEOIP,FASTLY)geoip:google(GEOIP,GOOGLE)geoip:netflix(GEOIP,NETFLIX)geoip:telegram(GEOIP,TELEGRAM)geoip:twitter(GEOIP,TWITTER)geoip:tor(GEOIP,TOR)[!NOTE] 如果无法访问域名
raw.githubusercontent.com,可以使用第二个地址cdn.jsdelivr.net。 如果无法访问域名cdn.jsdelivr.net,可以将其替换为fastly.jsdelivr.net。*.sha256sum 为校验文件。
本项目发布的所有 GeoIP 文件,请查看 release 分支。以下是部分格式 GeoIP 文件的下载地址和使用方法:
需要先下载 .dat 格式文件,并放置在程序目录内。
"routing": {
"rules": [
{
"type": "field",
"outboundTag": "Direct",
"ip": [
"geoip:cn",
"geoip:private",
"ext:cn.dat:cn",
"ext:private.dat:private",
"ext:geoip-only-cn-private.dat:cn",
"ext:geoip-only-cn-private.dat:private"
]
},
{
"type": "field",
"outboundTag": "Proxy",
"ip": [
"geoip:us",
"geoip:jp",
"geoip:facebook",
"geoip:telegram",
"ext:geoip-asn.dat:facebook",
"ext:geoip-asn.dat:telegram"
]
}
]
}
geodata-mode: true
geox-url:
geoip: "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/geoip.dat"
需要先下载 .dat 格式文件,并放置在 hysteria 程序目录内。
direct(geoip:cn)
proxy(geoip:telegram)
proxy(geoip:us)
需要先下载 .dat 格式文件,并放置在 Trojan-Go 程序目录内。
"router": {
"enabled": true,
"bypass": ["geoip:cn"],
"proxy": ["geoip:telegram", "geoip:us"],
"block": ["geoip:jp"],
"default_policy": "proxy",
"geoip": "./geoip.dat"
}
此 dat 格式文件不能用于 Nginx。
所有国家/地区、新增类别的 dat 格式文件,请查看本项目 release 分支下的 dat 目录。
geoip:cn 和 geoip:private):
geoip:cn):
geoip:private):
部分国家/地区类别:
新增类别:
需要先下载 .mmdb 格式文件,命名为 Country.mmdb,并放置在 Clash 程序目录内。
rules:
- GEOIP,PRIVATE,policy,no-resolve
- GEOIP,FACEBOOK,policy
- GEOIP,CN,policy,no-resolve
geodata-mode: false
geox-url:
mmdb: "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/Country.mmdb"
asn: "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/GeoLite2-ASN.mmdb"
需要将下载地址填入到 Shadowrocket 的设置中。
[Rule]
GEOIP,PRIVATE,DIRECT
GEOIP,FACEBOOK,PROXY
GEOIP,CN,DIRECT
需要将下载地址填入到 Quantumult X 的设置中。
[filter_local]
GEOIP,PRIVATE,DIRECT
GEOIP,FACEBOOK,PROXY
GEOIP,CN,DIRECT
需要将下载地址填入到 Surge 的设置中。
[Rule]
GEOIP,PRIVATE,policy,no-resolve
GEOIP,FACEBOOK,policy
GEOIP,CN,policy,no-resolve
1️⃣ 本项目生成的国家/地区类型 mmdb 文件:
适用于 Nginx,需要配合 ngx_http_geoip2_module 模块使用。
本项目生成的 mmdb 格式文件中,国家/地区类别保留了
Continent和Country里的所有字段,新增类别和GEOIP,PRIVATE类别只保留了Country里的iso_code(两位英文字母表示的国家/地区代号)字段。关于 Maxmind 官方GeoIP2-Country.mmdb和GeoLite2-Country.mmdb数据文件的完整字段,请查看代码。
GEOIP,PRIVATE 类别,不包含上述新增类别。建议优先使用):
GEOIP,PRIVATE 类别,以及上述新增类别。但由于 MaxMind mmdb 格式限制,部分国家/地区类别的 IP 地址数据不如上述 Country-without-asn.mmdb 准确):
GEOIP,CN 和 GEOIP,PRIVATE):
2️⃣ MaxMind 官方版国家/地区类型 mmdb 文件:
适用于 Nginx,需要配合 ngx_http_geoip2_module 模块使用。
3️⃣ MaxMind 官方版 ASN 类型 mmdb 文件:
适用于 mihomo、Shadowrocket、Surge。
"route": {
"rules": [
{
"rule_set": "geoip-cn",
"outbound": "direct"
},
{
"rule_set": "geoip-us",
"outbound": "block"
}
],
"rule_set": [
{
"tag": "geoip-cn",
"type": "remote",
"format": "binary",
"url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/srs/cn.srs"
},
{
"tag": "geoip-us",
"type": "remote",
"format": "binary",
"url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/srs/us.srs"
}
]
}
适用于 sing-box。
所有国家/地区、新增类别的 SRS 格式文件,请查看本项目 release 分支下的 srs 目录。
部分国家/地区类别:
新增类别:
rule-providers:
cn-cidr:
type: http
behavior: ipcidr
format: mrs
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/mrs/cn.mrs"
path: ./mrs/geoip/cn.mrs
interval: 86400
google-cidr:
type: http
behavior: ipcidr
format: mrs
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/mrs/google.mrs"
path: ./mrs/geoip/google.mrs
interval: 86400
rules:
- RULE-SET,cn-cidr,DIRECT
- RULE-SET,google-cidr,PROXY,no-resolve
适用于 mihomo。
所有国家/地区、新增类别的 MRS 格式文件,请查看本项目 release 分支下的 mrs 目录。
部分国家/地区类别:
新增类别:
rule-providers:
cn-cidr:
type: http
behavior: ipcidr
format: yaml
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/clash/ipcidr/cn.txt"
path: ./ruleset/ipcidr/cn.yaml
interval: 86400
telegram-cidr:
type: http
behavior: ipcidr
format: yaml
url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/clash/ipcidr/telegram.txt"
path: ./ruleset/ipcidr/telegram.yaml
interval: 86400
rules:
- RULE-SET,cn-cidr,DIRECT
- RULE-SET,telegram-cidr,PROXY,no-resolve
适用于 Clash Premium、mihomo。
所有国家/地区、新增类别的 Clash ruleset 格式文件,请查看本项目 release 分支下的 clash 目录。
部分国家/地区类别:
新增类别:
[Rule]
RULE-SET,https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/surge/us.txt,REJECT
RULE-SET,https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/surge/cn.txt,DIRECT
RULE-SET,https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/surge/telegram.txt,PROXY,no-resolve
适用于 Surge。
所有国家/地区、新增类别的 Surge ruleset 格式文件,请查看本项目 release 分支下的 surge 目录。
部分国家/地区类别:
新增类别:
allow 和 deny 格式文件所有国家/地区、新增类别的 Nginx allow 和 deny 格式文件,请查看本项目 release 分支下的 nginx 目录。
所有国家/地区、新增类别的纯文本 txt 格式文件,请查看本项目 release 分支下的 text 目录。
部分国家/地区类别:
新增类别:
[!NOTE] 如果需要使用 MaxMind 官方 GeoLite2 数据文件,需要提前从 MaxMind 下载,或者从本项目 release 分支下载(文件名以
GeoLite2为前缀的文件),并解压缩到名为geolite2的目录。
configuration.md 配置说明文档,修改自己仓库内的配置文件 config.json 和 GitHub Workflow .github/workflows/build.ymlgit clone https://github.com/Loyalsoldier/geoip.gitcd geoipconfiguration.md 配置说明文档,修改配置文件 config.jsongo run ./ convert -c ./config.json本项目配置文件 config.json 有两个概念:input 和 output。input 指数据源(data source)及其输入格式,output 指数据的去向(data destination)及其输出格式。CLI 的作用就是通过读取配置文件中的选项,聚合用户提供的所有数据源,去重,将其转换为目标格式,并输出到文件。
These two concepts in configuration file config.json are notable: input and output. The input is the data source and its input format, whereas the output is the destination of the converted data and its output format. What the CLI does is to aggregate all input format data, then convert them to output format and write them to GeoIP files by using the options in the config file.
关于每种格式所支持的配置选项,查看本项目 configuration.md 配置说明文档。
支持的 input 输入格式:
1.1.1.1 或 1.0.0.0/24)1.1.1.1 或 1.0.0.0/24)192.168.0.0/16 和 127.0.0.0/8)geoip.dat)GeoLite2-Country.mmdb)GeoLite2-ASN-CSV.zip)GeoLite2-Country-CSV.zip)dbip-country-lite.mmdb)country.mmdb)geoip-cn.mrs)geoip-cn.srs)支持的 output 输出格式:
1.0.0.0/24)1.0.0.0/24)geoip.dat)GeoLite2-Country.mmdb)dbip-country-lite.mmdb)country.mmdb)geoip-cn.mrs)geoip-cn.srs)由于 MaxMind、DB-IP、IPInfo 的 mmdb 文件格式的限制,当不同列表的 IP 或 CIDR 数据有交集或重复项时,后写入的列表的 IP 或 CIDR 数据会覆盖(overwrite)之前已写入的列表的数据。譬如,IP 1.1.1.1 同属于列表 AU 和列表 Cloudflare。如果 Cloudflare 在 AU 之后写入,则 IP 1.1.1.1 归属于列表 Cloudflare。
为了确保某些指定的列表、被修改的列表一定囊括属于它的所有 IP 或 CIDR 数据,可在 output 相应输出格式的配置中增加选项 overwriteList,该选项中指定的列表会在最后逐一写入,列表中最后一项优先级最高。若已设置选项 wantedList,则无需设置 overwriteList。wantedList 中指定的列表会在最后逐一写入,列表中最后一项优先级最高。
可通过 go install -v github.com/Loyalsoldier/geoip@latest 直接安装 CLI 工具。
CLI 提供的功能如下:
input 和 output 格式(list)convert)lookup)merge)$ ./geoip
geoip is a convenient tool to merge, convert and lookup IP & CIDR from various formats of geoip data.
Usage:
geoip [command]
Available Commands:
convert Convert geoip data from one format to another by using config file
help Help about any command
list List all available input and output formats
lookup Lookup specified IP or CIDR in specified lists
merge Merge plaintext IP & CIDR from standard input, then print to standard output
Flags:
-h, --help help for geoip
Use "geoip [command] --help" for more information about a command.
input 和 output 格式(list)$ ./geoip list
All available input formats:
- clashRuleSet (Convert ipcidr type of Clash RuleSet to other formats)
- clashRuleSetClassical (Convert classical type of Clash RuleSet to other formats (just processing IP & CIDR lines))
- cutter (Remove data from previous steps)
- dbipCountryMMDB (Convert DB-IP country mmdb database to other formats)
- ipinfoCountryMMDB (Convert IPInfo country mmdb database to other formats)
- json (Convert JSON data to other formats)
- maxmindGeoLite2ASNCSV (Convert MaxMind GeoLite2 ASN CSV data to other formats)
- maxmindGeoLite2CountryCSV (Convert MaxMind GeoLite2 country CSV data to other formats)
- maxmindMMDB (Convert MaxMind mmdb database to other formats)
- mihomoMRS (Convert mihomo MRS data to other formats)
- private (Convert LAN and private network CIDR to other formats)
- singboxSRS (Convert sing-box SRS data to other formats)
- stdin (Accept plaintext IP & CIDR from standard input, separated by newline)
- surgeRuleSet (Convert Surge RuleSet to other formats (just processing IP & CIDR lines))
- test (Convert specific CIDR to other formats (for test only))
- text (Convert plaintext IP & CIDR to other formats)
- v2rayGeoIPDat (Convert V2Ray GeoIP dat to other formats)
All available output formats:
- clashRuleSet (Convert data to ipcidr type of Clash RuleSet)
- clashRuleSetClassical (Convert data to classical type of Clash RuleSet)
- dbipCountryMMDB (Convert data to DB-IP country mmdb database format)
- ipinfoCountryMMDB (Convert data to IPInfo country mmdb database format)
- lookup (Lookup specified IP or CIDR from various formats of data)
- maxmindMMDB (Convert data to MaxMind mmdb database format)
- mihomoMRS (Convert data to mihomo MRS format)
- singboxSRS (Convert data to sing-box SRS format)
- stdout (Convert data to plaintext CIDR format and output to standard output)
- surgeRuleSet (Convert data to Surge RuleSet)
- text (Convert data to plaintext CIDR format)
- v2rayGeoIPDat (Convert data to V2Ray GeoIP dat format)
merge)$ curl -s https://core.telegram.org/resources/cidr.txt | ./geoip merge -t ipv4
91.105.192.0/23
91.108.4.0/22
91.108.8.0/21
91.108.16.0/21
91.108.56.0/22
149.154.160.0/20
185.76.151.0/24
convert)$ ./geoip convert -c config.json
2021/08/29 12:11:35 ✅ [v2rayGeoIPDat] geoip.dat --> output/dat
2021/08/29 12:11:35 ✅ [v2rayGeoIPDat] geoip-only-cn-private.dat --> output/dat
2021/08/29 12:11:35 ✅ [v2rayGeoIPDat] geoip-asn.dat --> output/dat
2021/08/29 12:11:35 ✅ [v2rayGeoIPDat] cn.dat --> output/dat
2021/08/29 12:11:35 ✅ [v2rayGeoIPDat] private.dat --> output/dat
2021/08/29 12:11:39 ✅ [maxmindMMDB] Country.mmdb --> output/maxmind
2021/08/29 12:11:39 ✅ [maxmindMMDB] Country-only-cn-private.mmdb --> output/maxmind
2021/08/29 12:11:39 ✅ [text] netflix.txt --> output/text
2021/08/29 12:11:39 ✅ [text] telegram.txt --> output/text
2021/08/29 12:11:39 ✅ [text] cn.txt --> output/text
2021/08/29 12:11:39 ✅ [text] cloudflare.txt --> output/text
2021/08/29 12:11:39 ✅ [text] cloudfront.txt --> output/text
2021/08/29 12:11:39 ✅ [text] facebook.txt --> output/text
2021/08/29 12:11:39 ✅ [text] fastly.txt --> output/text
2021/08/29 12:11:45 ✅ [singboxSRS] netflix.txt --> output/srs
2021/08/29 12:11:45 ✅ [singboxSRS] telegram.txt --> output/srs
2021/08/29 12:11:45 ✅ [singboxSRS] cn.txt --> output/srs
2021/08/29 12:11:45 ✅ [singboxSRS] cloudflare.txt --> output/srs
2021/08/29 12:11:45 ✅ [singboxSRS] cloudfront.txt --> output/srs
2021/08/29 12:11:45 ✅ [singboxSRS] facebook.txt --> output/srs
2021/08/29 12:11:45 ✅ [singboxSRS] fastly.txt --> output/srs
2021/08/29 12:11:50 ✅ [mihomoMRS] netflix.txt --> output/mrs
2021/08/29 12:11:50 ✅ [mihomoMRS] telegram.txt --> output/mrs
2021/08/29 12:11:50 ✅ [mihomoMRS] cn.txt --> output/mrs
2021/08/29 12:11:50 ✅ [mihomoMRS] cloudflare.txt --> output/mrs
2021/08/29 12:11:50 ✅ [mihomoMRS] cloudfront.txt --> output/mrs
2021/08/29 12:11:50 ✅ [mihomoMRS] facebook.txt --> output/mrs
2021/08/29 12:11:50 ✅ [mihomoMRS] fastly.txt --> output/mrs
lookup)可能的返回结果:
falsefalsetrueau,cloudflare# ================= One-time Mode ================= #
# 从 text 格式的本地文件(只包含一个类别)中查找某个 IP 地址
# lookup IP from local file (with only one list) in text format
$ ./geoip lookup -f text -u ./cn.txt 1.0.1.1
true
# 从 text 格式的本地文件(只包含一个类别)中查找某个 IP 地址
# lookup IP from local file (with only one list) in text format
$ ./geoip lookup -f text -u ./cn.txt 2.2.2.2
false
# 从 text 格式的本地文件(只包含一个类别)中查找某个 CIDR
# lookup CIDR from local file (with only one list) in text format
$ ./geoip lookup -f text -u ./cn.txt 1.0.1.1/24
true
# 从 text 格式的本地文件(只包含一个类别)中查找某个 CIDR
# lookup CIDR from local file (with only one list) in text format
$ ./geoip lookup -f text -u ./cn.txt 1.0.1.1/23
false
# 从 text 格式的远程 URL(只包含一个类别)中查找某个 IP 地址
# lookup IP from remote URL (with only one list) in text format
$ ./geoip lookup -f text -u https://example.com/cn.txt 1.0.1.1
true
# 从 v2rayGeoIPDat 格式的本地文件(只包含一个类别)中查找某个 IP 地址
# lookup IP from local file (with only one list) in v2rayGeoIPDat format
$ ./geoip lookup -f v2rayGeoIPDat -u ./cn.dat 1.0.1.1
true
# 从 v2rayGeoIPDat 格式的本地文件(包含多个类别)中查找某个 IP 地址
# lookup IP from local file (with multiple lists) in v2rayGeoIPDat format
$ ./geoip lookup -f v2rayGeoIPDat -u ./geoip.dat 1.0.1.1
cn
# 从 v2rayGeoIPDat 格式的本地文件(包含多个类别)中查找某个 IP 地址
# lookup IP from local file (with multiple lists) in v2rayGeoIPDat format
$ ./geoip lookup -f v2rayGeoIPDat -u ./geoip.dat 1.0.0.1
au,cloudflare
# 从 v2rayGeoIPDat 格式的远程 URL(包含多个类别)中查找某个 CIDR
# lookup CIDR from remote URL (with multiple lists) in v2rayGeoIPDat format
$ ./geoip lookup -f v2rayGeoIPDat -u https://example.com/geoip.dat 1.0.0.1/24
au,cloudflare
# ================= REPL Mode ================= #
# 从 text 格式的本地文件(只包含一个类别)中查找某个 IP 地址或 CIDR
# lookup IP or CIDR from local file (with only one list) in text format
$ ./geoip lookup -f text -u ./cn.txt
Enter IP or CIDR (type "exit" to quit):
>> 1.0.1.1
true
>> 1.0.1.1/24
true
>> 1.0.1.1/23
false
>> 2.2.2.2
false
>> 2.2.2.2/24
false
>> 300.300.300.300
false
>> 300.300.300.300/24
false
>> exit
# 从 text 格式的远程 URL(只包含一个类别)中查找某个 IP 地址或 CIDR
# lookup IP or CIDR from remote URL (with only one list) in text format
$ ./geoip lookup -f text -u https://example.com/cn.txt
Enter IP or CIDR (type "exit" to quit):
>> 1.0.1.1
true
>> 1.0.1.1/24
true
>> 1.0.1.1/23
false
>> 2.2.2.2
false
>> 2.2.2.2/24
false
>> 300.300.300.300
false
>> 300.300.300.300/24
false
>> exit
# 从 v2rayGeoIPDat 格式的本地文件(只包含一个类别)中查找某个 IP 地址或 CIDR
# lookup IP or CIDR from local file (with only one list) in v2rayGeoIPDat format
$ ./geoip lookup -f v2rayGeoIPDat -u ./cn.dat
Enter IP or CIDR (type "exit" to quit):
>> 1.0.1.1
true
>> 1.0.1.1/24
true
>> 1.0.1.1/23
false
>> 2.2.2.2
false
>> 2.2.2.2/24
false
>> 300.300.300.300
false
>> 300.300.300.300/24
false
>> exit
# 从 v2rayGeoIPDat 格式的远程 URL(包含多个类别)中查找某个 IP 地址或 CIDR
# lookup IP or CIDR from remote URL (with multiple list) in v2rayGeoIPDat format
$ ./geoip lookup -f v2rayGeoIPDat -u https://example.com/geoip.dat
Enter IP or CIDR (type "exit" to quit):
>> 1.0.1.1
cn
>> 1.0.1.1/24
cn
>> 1.0.1.1/23
false
>> 1.0.0.1
au,cloudflare
>> 1.0.0.1/24
au,cloudflare
>> 300.300.300.300
false
>> 300.300.300.300/24
false
>> exit
CC-BY-SA-4.0 and GPL-3.0
This product includes GeoLite2 data created by MaxMind, available from MaxMind.
Go
100.0%