Skip to content

xjbeta/geoip

 
 

Repository files navigation

简介

本项目每日自动生成 GeoIP 文件,同时提供命令行界面(CLI)供用户自行定制 GeoIP 文件,包括但不限于 V2Ray dat 格式路由规则文件 geoip.dat 和 MaxMind mmdb 格式文件 Country.mmdb

This project releases GeoIP files automatically every day. It also provides a command line interface(CLI) for users to customize their own GeoIP files, included but not limited to V2Ray dat format file geoip.dat and MaxMind mmdb format file Country.mmdb.

与上游 Loyalsoldier/geoip 的区别

  • 上游 Loyalsoldier/geoip 使用的海外数据库是 MaxMind 提供的 GeoLite2。 MaxMind 所提供 Geo2Country 这几年的准确度并不好。很多 IP 的位置信息都有问题。 而本工程使用了近几年数据更加准确的 IPInfo.io 的 Free IP to Country 数据库
  • MaxMind 的 Geo2Country 数据库是每周五更新一次,而 ipinfo.io 的 Free IP to Country 数据库是每天更新一次。
  • CI每日生成的MMDB中,并不包含任何新增类别,剔除了ipip-cn的数据库,仅构建原始的ipinfo的mmdb数据库

与官方版 GeoIP 的区别

  • 海外/中国大陆的 IPv4 & IPv6 数据库 使用了IPInfo.io 的 Free IP to Country 数据库 而不是 MaxMind 提供的 GeoLite2
  • 新增类别支持(方便有特殊需求的用户使用,需要自己修改配置文件开启,可以参考config.old):
    • geoip:cloudflareGEOIP,CLOUDFLARE
    • geoip:cloudfrontGEOIP,CLOUDFRONT
    • geoip:facebookGEOIP,FACEBOOK
    • geoip:fastlyGEOIP,FASTLY
    • geoip:googleGEOIP,GOOGLE
    • geoip:netflixGEOIP,NETFLIX
    • geoip:telegramGEOIP,TELEGRAM
    • geoip:twitterGEOIP,TWITTER

参考配置

Clash 中使用本项目 .mmdb 格式文件的参考配置:

rules:
  - GEOIP,CN,policy
  - GEOIP,US,policy
  - GEOIP,CountryCode,policy

Leaf 中使用本项目 .mmdb 格式文件的参考配置,查看官方 README

本工程生出的 Country.mmdb 数据库在 QuantmultX 中同样可用。

下载地址

如果无法访问域名 raw.githubusercontent.com,可以使用第二个地址 cdn.jsdelivr.net。 *.sha256sum 为校验文件。

V2Ray dat 格式路由规则文件

适用于 V2RayXray-coreTrojan-Go

  • CI 生成的 DAT 文件超出了 Github 的文件大小限制(100M),无法 Push 到 release 分支,目前只能自己本地生成使用

MaxMind mmdb 格式文件

适用于 ClashLeaf

定制 GeoIP 文件

可通过以下几种方式定制 GeoIP 文件:

  • 在线生成Fork 本仓库后,修改自己仓库内的配置文件 config.json 和 GitHub Workflow .github/workflows/build.yml
  • 本地生成
    • 安装 GolangGit
    • 拉取项目代码: git clone https://github.com/JohnnySun/geoip.git
    • 进入项目根目录:cd geoip
    • 修改配置文件 config.json
    • 运行代码:go run ./

特别说明:

  • 在线生成Fork 本项目后,如果需要使用 MaxMind GeoLite2 Country CSV 数据文件,需要在自己仓库的 [Settings] 选项卡的 [Secrets] 页面中添加一个名为 MAXMIND_GEOLITE2_LICENSEIPINFO_TOKEN 的 secret,否则 GitHub Actions 会运行失败。这个 secret 的值为 MAXMIND 账号的 LICENSE KEY 与 IPInfo.io 的 Token,需要注册 MAXMIND 账号后,在个人账号管理页面左侧边栏的 [Services] 项下的 [My License Key] 里生成MAXMIND_GEOLITE2_LICENSE,注册 注册 IPinfo.io 账号后,在Account左侧边栏的 [Home] 选项卡中找到 IPINFO_TOKEN
  • 本地生成:如果需要使用 MaxMind GeoLite2 Country CSV 数据文件(GeoLite2-Country-CSV.zip)以及 IPInfo.io Free IP to Country 数据文件(country.csv.gz),需要提前从 MaxMind & IPInfo.io 下载,或从本项目 release 分支下载,将(GeoLite2-Country-CSV.zip)并解压缩到名为 geolite2 的目录。

概念解析

本项目有两个概念:inputoutputinput 指数据源(data source)及其输入格式,output 指数据的去向(data destination)及其输出格式。CLI 的作用就是通过读取配置文件中的选项,聚合用户提供的所有数据源,去重,将其转换为目标格式,并输出到文件。

These two concepts 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.

支持的格式

关于每种格式所支持的配置选项,查看本项目 config-example.json 文件。

支持的 input 输入格式:

  • text:纯文本 IP 和 CIDR(例如:1.1.1.11.0.0.0/24
  • private:局域网和私有网络 CIDR(例如:192.168.0.0/16127.0.0.0/8
  • cutter:用于裁剪前置步骤中的数据
  • v2rayGeoIPDat:V2Ray GeoIP dat 格式(geoip.dat
  • maxmindMMDB:MaxMind mmdb 数据格式(GeoLite2-Country.mmdb
  • maxmindGeoLite2CountryCSV:MaxMind GeoLite2 country CSV 数据(GeoLite2-Country-CSV.zip
  • clashRuleSetClassicalclassical 类型的 Clash RuleSet
  • clashRuleSetipcidr 类型的 Clash RuleSet
  • surgeRuleSetSurge RuleSet

支持的 output 输出格式:

注意事项

由于 MaxMind mmdb 文件格式的限制,当不同列表的 IP 或 CIDR 数据有交集或重复项时,后写入的列表的 IP 或 CIDR 数据会覆盖(overwrite)之前已写入的列表的数据。譬如,IP 1.1.1.1 同属于列表 AU 和列表 Cloudflare。如果 CloudflareAU 之后写入,则 IP 1.1.1.1 归属于列表 Cloudflare

为了确保某些指定的列表、被修改的列表一定囊括属于它的所有 IP 或 CIDR 数据,可在 output 输出格式为 maxmindMMDB 的配置中增加选项 overwriteList,该选项中指定的列表会在最后逐一写入,列表中最后一项优先级最高。若已设置选项 wantedList,则无需设置 overwriteListwantedList 中指定的列表会在最后逐一写入,列表中最后一项优先级最高。

CLI 功能展示

可通过 go install -v github.com/JohnnySun/geoip@latest 直接安装 CLI。

$ ./geoip -h
Usage of ./geoip:
  -c string
    	URI of the JSON format config file, support both local file path and remote HTTP(S) URL (default "config.json")
  -l	List all available input and output formats

$ ./geoip -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

$ ./geoip -l
All available input formats:
  - v2rayGeoIPDat (Convert V2Ray GeoIP dat to other formats)
  - maxmindMMDB (Convert MaxMind mmdb database to other formats)
  - maxmindGeoLite2CountryCSV (Convert MaxMind GeoLite2 country CSV data to other formats)
  - private (Convert LAN and private network CIDR to other formats)
  - text (Convert plaintext IP & CIDR to other formats)
  - clashRuleSetClassical (Convert classical type of Clash RuleSet to other formats (just processing IP & CIDR lines))
  - clashRuleSet (Convert ipcidr type of Clash RuleSet to other formats)
  - surgeRuleSet (Convert Surge RuleSet to other formats (just processing IP & CIDR lines))
  - cutter (Remove data from previous steps)
  - test (Convert specific CIDR to other formats (for test only))
All available output formats:
  - v2rayGeoIPDat (Convert data to V2Ray GeoIP dat format)
  - maxmindMMDB (Convert data to MaxMind mmdb database format)
  - clashRuleSetClassical (Convert data to classical type of Clash RuleSet)
  - clashRuleSet (Convert data to ipcidr type of Clash RuleSet)
  - surgeRuleSet (Convert data to Surge RuleSet)
  - text (Convert data to plaintext CIDR format)

License

CC-BY-SA-4.0

This product includes GeoLite2 data created by MaxMind, available from MaxMind.

This product includes Free IP to Country data created by IPInfo.io, available from IPInfo.io.

项目 Star 数增长趋势

Stargazers over time

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 98.5%
  • Shell 1.5%