loyalsoldier/geoip

repository·master·Indexed 27 days ago

https://github.com/loyalsoldier/geoip

A project providing customized GeoIP data files and a CLI tool for generating custom datasets. It supports multiple formats including V2Ray (.dat), MaxMind (.mmdb), sing-box (SRS), mihomo (MRS), Clash, Surge, and Nginx. The project extends MaxMind GeoLite2 Country CSV data with enhanced China IP data and specialized categories for services such as Cloudflare, Google, Netflix, and Telegram.

Tokens
13.4K
Snippets
46
Records
87
Agent score
87%

What's inside loyalsoldier-geoip

  1. Overview of GeoIP formats and customization

    master

    The loyalsoldier/geoip project automatically generates various GeoIP data file formats every Thursday. It also provides a CLI tool for users to customize their own GeoIP files.

    Supported formats include:

    • V2Ray dat format (geoip.dat)
    • MaxMind mmdb format (Country.mmdb, including GeoIP2-Country.mmdb and GeoLite2-Country.mmdb)
    • sing-box SRS format
    • mihomo MRS format
    • Clash ruleset files
    • Surge ruleset files
    • Nginx allow/deny lists
  2. Generate custom GeoIP files locally

    master

    To build your own GeoIP files on your local machine, you need to install Golang and Git, clone the repository, configure your config.json according to the configuration.md documentation, and run the conversion tool.

    Prerequisites:

    Steps:

    1. Clone the repository: git clone https://github.com/Loyalsoldier/geoip.git
    2. Navigate to the root directory: cd geoip
    3. Modify config.json based on the project's configuration guide.
    4. Execute the conversion command.
    git clone https://github.com/Loyalsoldier/geoip.git
    cd geoip
    go run ./ convert -c ./config.json
  3. Use GeoIP rulesets in Surge

    master

    To use these GeoIP files in Surge, add RULE-SET entries to your [Rule] section. You can point directly to the jsDelivr CDN URLs for automatic updates.

    Example configuration for rejecting US traffic, directing China traffic, and proxying Telegram traffic:

    [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
  4. Download GeoIP .dat files

    master

    GeoIP files in .dat format are available for various proxy tools. You can download them from the release branch of the repository.

    Primary Download Mirrors:

    • https://raw.githubusercontent.com/Loyalsoldier/geoip/release/
    • https://cdn.jsdelivr.net/gh/Loyalsoldier/geoip@release/
    • https://fastly.jsdelivr.net/gh/Loyalsoldier/geoip@release/ (Alternative if jsdelivr is inaccessible)

    Available Formats:

    • geoip.dat: Full GeoIP dataset.
    • geoip-only-cn-private.dat: Lightweight version containing only geoip:cn and geoip:private.
    • geoip-asn.dat: Lightweight version containing only new categories (e.g., Facebook, Telegram).
    • cn.dat: Contains only geoip:cn.
    • private.dat: Contains only geoip:private.
    • Country-specific files (e.g., cn.dat, us.dat, jp.dat) are located in the /dat subdirectory of the release branch.

    Always verify integrity using the corresponding .sha256sum files.

  5. Configure MaxMind mmdb in mihomo

    master

    In mihomo, set geodata-mode to false and provide the URLs for your mmdb and asn files under the geox-url key.

    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"
  6. Configure sing-box using SRS rule sets

    master

    In sing-box, define rule_set entries with type: "remote" and format: "binary" to use the provided .srs files. Then, reference these tags in your route.rules configuration.

    "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"
        }
      ]
    }
  7. Configure Clash ruleset for Clash Premium and mihomo

    master

    You can use the provided GeoIP rulesets in Clash Premium or mihomo by defining rule-providers with type: http and behavior: ipcidr. This allows the client to automatically fetch and update the IP CIDR lists.

    Note: The format should be set to yaml for these rulesets.

    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
  8. Configure the GeoIP conversion tool using JSON

    master

    The project uses a JSON configuration file to define data transformation pipelines. The configuration must contain two primary arrays: input and output. Each array contains one or more configuration objects specifying the format for that stage of the pipeline.

    Example structure:

    {
      "input":  [],
      "output": []
    }