Skip to content

Commit

Permalink
Feat: support sing-box SRS format
Browse files Browse the repository at this point in the history
both as input and output
  • Loading branch information
Loyalsoldier committed Jun 23, 2024
1 parent 09fed9b commit a2f6391
Show file tree
Hide file tree
Showing 9 changed files with 576 additions and 34 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ jobs:
mkdir -p publish
mv ./output/dat/*.dat ./output/dat/*.sha256sum ./output/maxmind/*.mmdb ./output/maxmind/*.sha256sum *.gz *.zip ./publish/
cp -fpPR ./output/text ./publish
cp -fpPR ./output/srs ./publish
- name: Git push assets to "release" branch
run: |
Expand All @@ -115,7 +116,7 @@ jobs:
done
- name: Remove some files to avoid publishing to GitHub release
run: rm -rf ./publish/*.{gz,zip} ./publish/text
run: rm -rf ./publish/*.{gz,zip} ./publish/text ./publish/srs

- name: Upload files to GitHub release
uses: svenstaro/upload-release-action@v2
Expand Down
55 changes: 55 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# Binaries for programs and plugins
*.exe
*.exe~
Expand All @@ -19,3 +71,6 @@ data/
geolite2/
output/
geoip
*.dat
*.mmdb
*.srs
52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 简介

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

This project releases GeoIP files automatically every Thursday. 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`.
This project releases GeoIP files automatically every Thursday. 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`, MaxMind mmdb format file `Country.mmdb` and sing-box SRS format files.

## 与官方版 GeoIP 的区别

Expand Down Expand Up @@ -64,6 +64,37 @@ rules:
在 [Leaf](https://github.com/eycorsican/leaf) 中使用本项目 `.mmdb` 格式文件的参考配置,查看[官方 README](https://github.com/eycorsican/leaf/blob/master/README.zh.md#geoip)。

在 [sing-box](https://github.com/SagerNet/sing-box) 中使用本项目 `.srs` 格式文件的参考配置:

```json
"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://raw.githubusercontent.com/Loyalsoldier/geoip/release/srs/cn.srs"
},
{
"tag": "geoip-us",
"type": "remote",
"format": "binary",
"url": "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/srs/us.srs"
}
]
}
```

## 下载地址

> 如果无法访问域名 `raw.githubusercontent.com`,可以使用第二个地址 `cdn.jsdelivr.net`。
Expand Down Expand Up @@ -127,6 +158,12 @@ rules:
- [https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country-asn.mmdb.sha256sum](https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country-asn.mmdb.sha256sum)
- [https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/Country-asn.mmdb.sha256sum](https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/Country-asn.mmdb.sha256sum)

### sing-box SRS 格式路由规则文件

> 适用于 [sing-box](https://github.com/SagerNet/sing-box)。

请查看本项目 `release` 分支下 [output / srs](https://github.com/Loyalsoldier/geoip/tree/release/srs) 目录。

## 定制 GeoIP 文件

可通过以下几种方式定制 GeoIP 文件:
Expand Down Expand Up @@ -162,6 +199,7 @@ These two concepts are notable: `input` and `output`. The `input` is the data so
- **v2rayGeoIPDat**:V2Ray GeoIP dat 格式(`geoip.dat`)
- **maxmindMMDB**:MaxMind mmdb 数据格式(`GeoLite2-Country.mmdb`)
- **maxmindGeoLite2CountryCSV**:MaxMind GeoLite2 country CSV 数据(`GeoLite2-Country-CSV.zip`)
- **singboxSRS**:sing-box SRS 格式(`geoip-cn.srs`)
- **clashRuleSetClassical**:[classical 类型的 Clash RuleSet](https://github.com/Dreamacro/clash/wiki/premium-core-features#classical)
- **clashRuleSet**:[ipcidr 类型的 Clash RuleSet](https://github.com/Dreamacro/clash/wiki/premium-core-features#ipcidr)
- **surgeRuleSet**:[Surge RuleSet](https://manual.nssurge.com/rule/ruleset.html)
Expand All @@ -171,6 +209,7 @@ These two concepts are notable: `input` and `output`. The `input` is the data so
- **text**:纯文本 CIDR(例如:`1.0.0.0/24`)
- **v2rayGeoIPDat**:V2Ray GeoIP dat 格式(`geoip.dat`,适用于 [V2Ray](https://github.com/v2fly/v2ray-core)、[Xray-core](https://github.com/XTLS/Xray-core) 和 [Trojan-Go](https://github.com/p4gefau1t/trojan-go))
- **maxmindMMDB**:MaxMind mmdb 数据格式(`GeoLite2-Country.mmdb`,适用于 [Clash](https://github.com/Dreamacro/clash) 和 [Leaf](https://github.com/eycorsican/leaf))
- **singboxSRS**:sing-box SRS 格式(`geoip-cn.srs`,适用于 [sing-box](https://github.com/SagerNet/sing-box))
- **clashRuleSetClassical**:[classical 类型的 Clash RuleSet](https://github.com/Dreamacro/clash/wiki/premium-core-features#classical)
- **clashRuleSet**:[ipcidr 类型的 Clash RuleSet](https://github.com/Dreamacro/clash/wiki/premium-core-features#ipcidr)
- **surgeRuleSet**:[Surge RuleSet](https://manual.nssurge.com/rule/ruleset.html)
Expand Down Expand Up @@ -207,12 +246,20 @@ $ ./geoip -c config.json
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
$ ./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)
- singboxSRS (Convert sing-box SRS 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))
Expand All @@ -223,6 +270,7 @@ All available input formats:
All available output formats:
- v2rayGeoIPDat (Convert data to V2Ray GeoIP dat format)
- maxmindMMDB (Convert data to MaxMind mmdb database format)
- singboxSRS (Convert data to sing-box SRS 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)
Expand Down
4 changes: 4 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@
]
}
},
{
"type": "singboxSRS",
"action": "output"
},
{
"type": "text",
"action": "output"
Expand Down
19 changes: 13 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,31 @@ toolchain go1.21.10
require (
github.com/maxmind/mmdbwriter v1.0.0
github.com/oschwald/maxminddb-golang v1.13.0
github.com/sagernet/sing-box v1.9.3
github.com/v2fly/v2ray-core/v5 v5.16.1
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba
google.golang.org/protobuf v1.34.1
google.golang.org/protobuf v1.34.2
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/adrg/xdg v0.4.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/miekg/dns v1.1.59 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pires/go-proxyproto v0.7.0 // indirect
github.com/quic-go/quic-go v0.43.0 // indirect
github.com/sagernet/sing v0.4.1 // indirect
github.com/sagernet/sing-dns v0.2.0 // indirect
go.starlark.net v0.0.0-20230612165344-9532f5667272 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit a2f6391

Please sign in to comment.