Skip to content

Commit

Permalink
unpack geosite
Browse files Browse the repository at this point in the history
  • Loading branch information
Larvan2 committed Jan 15, 2024
1 parent 2825b6f commit c7bdde6
Show file tree
Hide file tree
Showing 7 changed files with 487 additions and 349 deletions.
33 changes: 22 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,30 @@ jobs:
GOOS=windows GOARCH=arm64 go build -o ./bin/geo-windows-arm64.exe ./cmd/geo
- name: Delete current release assets
uses: andreaswilli/delete-release-assets-action@v3.0.0
uses: 8Mi-Tech/delete-release-assets-action@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag: latest
tag: Prerelease-${{ github.ref_name }}
deleteOnlyFromDrafts: false

- name: Create and Upload Release
id: upload_release
uses: svenstaro/upload-release-action@v2
- name: Tag Repo
uses: richardsimko/[email protected]
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
release_name: "α"
tag: latest
file_glob: true
overwrite: true
file: ./bin/*
tag_name: Prerelease-${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set Env
run: |
echo "BUILDTIME=$(TZ=Asia/Shanghai date)" >> $GITHUB_ENV
shell: bash

- name: Upload Prerelease
uses: softprops/action-gh-release@v1
if: ${{ success() }}
with:
tag_name: Prerelease-${{ github.ref_name }}
files: |
bin/*
prerelease: true
generate_release_notes: true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ test/config/cache*
/output
.vscode/
.fleet/


*.dat
231 changes: 121 additions & 110 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,110 +1,121 @@
# geo

🗺An easy way to manage all your Geo resources.

Support GeoIP/GeoSite code lookup and converting among all popular GeoIP/GeoSite databases.

## Install

Requirements:

- [Go](https://go.dev) 1.20+

```shell
go install -v github.com/metacubex/geo/cmd/geo@master
```

## Usage

Type `geo help` for more details.

### Look up codes from existing Geo databases

The default directory to find Geo databases is
`~/.geo`. You can specify it through `-D` argument.

#### IP

```shell
geo look 223.5.5.5
```

```shell
geo look 2001:250::
```

#### Site

```shell
geo look example.com
```

```shell
geo look --no-resolve example.com
```

Supported databases for `look` command:

- MaxMind MMDB
- V2Ray dat GeoIP/GeoSite
- sing-geosite
- sing-geoip MMDB
- Meta-geoip MMDB

### Convert

#### IP

```shell
geo convert ip -i <input_type> -o <output_type> -f [output_filename] input_filename
```

```shell
geo convert ip -i v2ray -o meta ./geoip.dat
```

Available types:

- [MaxMind](https://github.com/Dreamacro/maxmind-geoip) (MMDB)
- [V2Ray-geoip](https://github.com/v2fly/geoip) (dat)
- [sing-geoip](https://github.com/SagerNet/sing-geoip) (MMDB)
- [Meta-geoip](https://github.com/MetaCubeX/meta-rules-dat) (MMDB)

Supported conversion pairs: (Column=From, Row=To)

| | MaxMind | V2Ray-geoip | sing-geoip | Meta-geoip |
| ---------- | :-----: | :---------: | :--------: | :--------: |
| MaxMind | - | | | |
| V2Ray | | - | | |
| sing-geoip ||| - ||
| Meta-geoip | || | - |

Conversion to MaxMind is not available for legal reasons.
Conversion to V2Ray is on the TODO list.

#### Site

```shell
geo convert site -i <input_type> -o <output_type> -f [output_filename] -c [country code] input_filename
```

```shell
geo convert site -i v2ray -o sing ./geosite.dat
```

Only v2ray -> sing conversion is supported for GeoSite.

## Frequently Asked Questions (FAQ)

### Why conversion MaxMind/sing-geoip -> Meta-geoip is not available?

Meta-geoip is designed to support IP with multiple results,
which will help users who use GeoIP functionality as IPList or IPSet.

For sources such as MaxMind and sing-geoip, which only have a single possible result,
according to the principle of Occam's razor, there is no need to convert to Meta-geoip database.
In the other hand, when there is only a single result,
the data structure of Meta-geoip and sing-geoip is completely consistent,
and even compatible with the parsing logic.

Clash.Meta supports all of these databases, so everything is well. :-)
# geo

🗺An easy way to manage all your Geo resources.

Support GeoIP/GeoSite code lookup and converting among all popular GeoIP/GeoSite databases.

## Install

Requirements:

- [Go](https://go.dev) 1.20+

```shell
go install -v github.com/metacubex/geo/cmd/geo@master
```

## Usage

Type `geo help` for more details.

### Look up codes from existing Geo databases

The default directory to find Geo databases is
`~/.geo`. You can specify it through `-D` argument.

#### IP

```shell
geo look 223.5.5.5
```

```shell
geo look 2001:250::
```

#### Site

```shell
geo look example.com
```

```shell
geo look --no-resolve example.com
```

Supported databases for `look` command:

- MaxMind MMDB
- V2Ray dat GeoIP/GeoSite
- sing-geosite
- sing-geoip MMDB
- Meta-geoip MMDB

### Convert

#### IP

```shell
geo convert ip -i <input_type> -o <output_type> -f [output_filename] input_filename
```

```shell
geo convert ip -i v2ray -o meta ./geoip.dat
```

Available types:

- [MaxMind](https://github.com/Dreamacro/maxmind-geoip) (MMDB)
- [V2Ray-geoip](https://github.com/v2fly/geoip) (dat)
- [sing-geoip](https://github.com/SagerNet/sing-geoip) (MMDB)
- [Meta-geoip](https://github.com/MetaCubeX/meta-rules-dat) (MMDB)

Supported conversion pairs: (Column=From, Row=To)

| | MaxMind | V2Ray-geoip | sing-geoip | Meta-geoip |
| ---------- | :-----: | :---------: | :--------: | :--------: |
| MaxMind | - | | | |
| V2Ray | | - | | |
| sing-geoip ||| - ||
| Meta-geoip | || | - |

Conversion to MaxMind is not available for legal reasons.
Conversion to V2Ray is on the TODO list.

#### Site

```shell
geo convert site -i <input_type> -o <output_type> -f [output_filename] -c [country code] input_filename
```

```shell
geo convert site -i v2ray -o sing ./geosite.dat
```

Only v2ray -> sing conversion is supported for GeoSite.

### Unpack

#### site

```shell
geo unpack site ./geosite.dat -d output -c cn
```

- -d output dir
- -c code, unpack all geosite if not set

## Frequently Asked Questions (FAQ)

### Why conversion MaxMind/sing-geoip -> Meta-geoip is not available?

Meta-geoip is designed to support IP with multiple results,
which will help users who use GeoIP functionality as IPList or IPSet.

For sources such as MaxMind and sing-geoip, which only have a single possible result,
according to the principle of Occam's razor, there is no need to convert to Meta-geoip database.
In the other hand, when there is only a single result,
the data structure of Meta-geoip and sing-geoip is completely consistent,
and even compatible with the parsing logic.

Clash.Meta supports all of these databases, so everything is well. :-)
17 changes: 17 additions & 0 deletions cmd/geo/cmd_unpack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"github.com/metacubex/geo/cmd/geo/internal/convert"
"github.com/spf13/cobra"
)

func init() {
// commandUnpack.AddCommand(convert.CommandIP)
commandUnpack.AddCommand(convert.CommandUnpackSite)
mainCommand.AddCommand(commandUnpack)
}

var commandUnpack = &cobra.Command{
Use: "unpack",
Short: "unpack geo resource",
}
17 changes: 9 additions & 8 deletions cmd/geo/internal/convert/args.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package convert

var (
fromType string
toType string
output string
code string
)
package convert

var (
fromType string
toType string
output string
code string
outDir string
)
Loading

0 comments on commit c7bdde6

Please sign in to comment.