{"id":13389920,"url":"https://github.com/JinnLynn/genpac","last_synced_at":"2025-03-13T14:32:14.498Z","repository":{"id":3212730,"uuid":"4247123","full_name":"JinnLynn/genpac","owner":"JinnLynn","description":"PAC/Dnsmasq/Wingy file Generator,  working with gfwlist, support custom rules.","archived":false,"fork":false,"pushed_at":"2025-03-09T12:32:31.000Z","size":44087,"stargazers_count":2169,"open_issues_count":0,"forks_count":315,"subscribers_count":80,"default_branch":"master","last_synced_at":"2025-03-09T13:30:06.959Z","etag":null,"topics":["dnsmasq","gfw","gfwlist","pac","pypi","python","wingy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JinnLynn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-05-07T07:01:56.000Z","updated_at":"2025-03-08T07:10:55.000Z","dependencies_parsed_at":"2024-01-17T16:08:02.799Z","dependency_job_id":"7f42ea44-bb21-4e59-b9f7-bef62bff980d","html_url":"https://github.com/JinnLynn/genpac","commit_stats":{"total_commits":114,"total_committers":4,"mean_commits":28.5,"dds":0.02631578947368418,"last_synced_commit":"2f466d28f403a9a5624e02edcd538475fe475fc8"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JinnLynn%2Fgenpac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JinnLynn%2Fgenpac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JinnLynn%2Fgenpac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JinnLynn%2Fgenpac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JinnLynn","download_url":"https://codeload.github.com/JinnLynn/genpac/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243158975,"owners_count":20245672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dnsmasq","gfw","gfwlist","pac","pypi","python","wingy"],"created_at":"2024-07-30T13:01:39.804Z","updated_at":"2025-03-13T14:32:14.465Z","avatar_url":"https://github.com/JinnLynn.png","language":"Python","funding_links":[],"categories":["Tutorial","Python","Python (1887)"],"sub_categories":["Windows Manager"],"readme":"# GenPAC\n\n[![pypi-version]][pypi] ![pypi-pyversions] [![pypi-license]][pypi] [![dev-version]](https://github.com/JinnLynn/genpac/tree/dev) [![build](https://github.com/JinnLynn/genpac/actions/workflows/build.yml/badge.svg)](https://github.com/JinnLynn/genpac/actions/workflows/build.yml) [![cook](https://github.com/JinnLynn/genpac/actions/workflows/cook.yml/badge.svg)](https://github.com/JinnLynn/genpac/actions/workflows/cook.yml)\n\n基于[gfwlist][]的多种代理软件配置文件生成工具，支持自定义规则\n\n目前支持的格式有: **PAC, Dnsmasq, V2Ray, Shadowsocks, Quantumult X, Shadowrocket, Surge, Wingy, Potatso** 和 **IP** (国别IP列表), **List** (gfwlist格式的列表), **Copy** (复制源)。[示例](https://github.com/JinnLynn/genpac/tree/cooked)\n\n**注意**: 生成后的规则不会匹配网址路径，只会检查域名(包括子域名)，如`|http://sub2.sub1.domain.com/path/to/file.ext` =\u003e `sub2.sub1.domain.com`\n\n## 安装\n\n```shell\n# 安装或更新\npip install genpac\n# 安装开发版本\npip install https://github.com/JinnLynn/genpac/archive/dev.tar.gz\n\n# 安装服务器组件\npip install genpac[server]\npip install \"genpac[server] @ https://github.com/JinnLynn/genpac/archive/dev.tar.gz\"\n\n# 卸载\npip uninstall genpac\n```\n\n## 使用方法\n\n### 命令行形式\n\n```shell\ngenpac [--version] [--help] [--init [PATH]] [--format FMT] [--output FILE] [--config FILE] [--proxy PROXY] [--gfwlist-url URL]\n              [--gfwlist-local FILE] [--gfwlist-update-local] [--gfwlist-disabled] [--gfwlist-decoded-save FILE] [--user-rule RULE]\n              [--user-rule-from FILE] [--template FILE] [--etag-cache] [--pac-proxy PROXY] [--pac-precise] [--pac-compress]\n              [--dnsmasq-dns DNS] [--dnsmasq-ipset IPSET] [--dnsmasq-nftset NFTSET] [--v2ray-proxy TAG] [--v2ray-direct TAG]\n              [--v2ray-default TAG] [--v2ray-format {json,yaml}] [--ip-cc CC] [--ip-family {4,6,all}] [--ssacl-geocn] [--list-raw]\n              [--qtx-no-direct] [--qtx-no-final] [--copy-source SRC] [--shadowrocket-policy POLICY] [--shadowrocket-no-direct]\n              [--shadowrocket-no-final] [--shadowrocket-set] [--surge-policy POLICY] [--surge-no-direct] [--surge-no-final] [--surge-set]\n              [--wingy-adapter-opts OPTS] [--wingy-rule-adapter-id ID]\n\n获取gfwlist生成多种格式的翻墙工具配置文件, 支持自定义规则\n\noptions:\n  --version, -v         版本信息\n  --help, -h            帮助信息\n  --init [PATH]         初始化配置和用户规则文件\n\n通用参数:\n  --format FMT, -f FMT  生成格式, 只有指定了格式, 相应格式的参数才可用\n                        可选: pac,dnsmasq,v2ray,ip,ssacl,list,qtx,copy,shadowrocket,surge,wingy,potatso\n  --output FILE, -o FILE\n                        输出到文件, 无此参数或FILE为-, 则输出到stdout\n  --config FILE, -c FILE\n                        从文件中读取配置信息\n  --proxy PROXY         在线获取外部数据时的代理, 如果可正常访问外部地址, 则无必要使用该选项\n                        格式: [PROTOCOL://][USERNAME:PASSWORD@]HOST:PORT\n                        其中协议、用户名、密码可选, 支持协议: http socks5 socks4 socks 如:\n                          http://127.0.0.1:8080\n                          SOCKS5://127.0.0.1:1080\n                          SOCKS5://username:password@127.0.0.1:1080\n  --gfwlist-url URL     gfwlist网址，无此参数或URL为空则使用默认地址, URL为-则不在线获取\n  --gfwlist-local FILE  本地gfwlist文件地址, 当在线地址获取失败时使用\n  --gfwlist-update-local\n                        当在线gfwlist成功获取且--gfwlist-local参数存在时, 更新gfwlist-local内容\n  --gfwlist-disabled    禁用gfwlist\n  --gfwlist-decoded-save FILE\n                        保存解码后的gfwlist, 仅用于测试\n  --user-rule RULE      自定义规则, 允许重复使用或在单个参数中使用`,`分割多个规则，如:\n                          --user-rule=\"@@sina.com\" --user-rule=\"||youtube.com\"\n                          --user-rule=\"@@sina.com,||youtube.com\"\n  --user-rule-from FILE\n                        从文件中读取自定义规则, 使用方法如--user-rule\n  --template FILE       自定义模板文件\n  --etag-cache          获取外部文件时是否使用If-None-Match头进行缓存检查\n\nPAC:\n  通过代理自动配置文件(PAC)系统或浏览器可自动选择合适的代理服务器\n\n  --pac-proxy PROXY     代理地址, 如 SOCKS5 127.0.0.1:8080; SOCKS 127.0.0.1:8080\n  --pac-precise         精确匹配模式\n  --pac-compress        压缩输出\n\nDNSMASQ:\n  Dnsmasq配合iptables/ipset、nftables/nftset可实现基于域名的透明代理\n\n  --dnsmasq-dns DNS     生成规则域名查询使用的DNS服务器，格式: HOST#PORT\n                        默认: 127.0.0.1#53\n  --dnsmasq-ipset IPSET\n                        使用ipset, 允许重复或使用`,`分割多个,\n                        如: GFWLIST,GFWLIST6\n  --dnsmasq-nftset NFTSET\n                        使用ntfset, 允许重复或使用`,`分割多个,\n                        如: 4#inet#TABLE#GFWLIST,6#inet#TABLE#GFWLIST6\n\nV2RAY:\n  V2Ray的路由规则\n\n  --v2ray-proxy TAG     代理标签，默认: proxy\n  --v2ray-direct TAG    直连标签，未指定则不输出直连规则\n  --v2ray-default TAG   默认标签，未指定则不输出默认规则\n  --v2ray-format {json,yaml}\n                        输出格式，默认: json\n\nIP:\n  国别IP地址列表\n\n  --ip-cc CC            国家代码(ISO 3166-1) 默认: CN\n  --ip-family {4,6,all}\n                        IP类型 可选: 4, 6, all 默认: 4\n\nSSACL:\n  Shadowsocks访问控制列表\n\n  --ssacl-geocn         国内IP不走代理，所有国外IP走代理\n\nLIST:\n  与GFWList格式相同的地址列表\n\n  --list-raw            明文，不进行base64编码\n\nQTX:\n  Quantumult X 的分流规则\n\n  --qtx-no-direct       不包含直连规则\n  --qtx-no-final        不包含FINAL规则\n\nCOPY:\n  IP地址列表\n\n  --copy-source SRC     来源, 网址或文件路径\n\nSHADOWROCKET:\n  Shadowrocket(小火箭)代理规则\n\n  --shadowrocket-policy POLICY\n                        代理规则策略: 默认: PROXY\n  --shadowrocket-no-direct\n                        不包含直连规则\n  --shadowrocket-no-final\n                        不包含FINAL规则\n  --shadowrocket-set    输出为规则集\n\nSURGE:\n  Surge代理规则\n\n  --surge-policy POLICY\n                        代理规则策略: 默认: PROXY\n  --surge-no-direct     不包含直连规则\n  --surge-no-final      不包含FINAL规则\n  --surge-set           输出为规则集\n\nWINGY:\n  Wingy是iOS下基于NEKit的代理App, 无可用参数\n  * 注意: 即将废弃 *\n\n  --wingy-adapter-opts OPTS\n                        adapter选项, 选项间使用`,`分割, 多个adapter使用`;`分割, 如:\n                          id:ap1,type:http,host:127.0.0.1,port:8080;id:ap2,type:socks5,host:127.0.0.1,port:3128\n  --wingy-rule-adapter-id ID\n                        生成规则使用的adapter ID\n\nPOTATSO:\n  Potatso2是iOS下基于NEKit的代理App, 无可用参数\n  * 注意: 即将废弃 *\n```\n\n### web服务形式\n\n支持以web形式自动生成及输出:\n\n```shell\n# 安装服务组件\npip install genpac[server]\npip install \"genpac[server] @ https://github.com/JinnLynn/genpac/archive/dev.tar.gz\"\n\n# 本地运行\ngenpac.server --config=\"/PATH/TO/CONFIG/FILE\"\n\n# Docker 运行\n# 测试\ndocker run --rm -p 8000:8000 jinnlynn/genpac\n# 自定义配置文件\ndocker run --rm -p 8000:8000 -v /PATH/TO/CONFIG/FILE:/app/etc/config.ini jinnlynn/genpac\n```\n\n配置参考见[example/server/config.ini][]\n\n## 配置文件\n\n支持通过 `--config` 参数读入配置信息，配置文件书写方法可参考[example/config.ini][]\n\n## 自定义规则\n\n支持通过 `--user-rule` 自定义单个规则或 `--user-rule-from` 读入自定义规则文件，这两个参数均可重复使用。\n\n自定义规则文件可参考[example/user-rules.txt][]\n\n自定义规则的语法与gfwlist相同，使用AdBlock Plus过滤规则( http://adblockplus.org/en/filters )，简述如下:\n\n1. 通配符支持，如 `*.example.com/*` 实际书写时可省略 `*` 为 `.example.com/`\n2. 正则表达式支持，以 `\\` 开始和结束，如 `\\[\\w]+:\\/\\/example.com\\\\`\n3. 例外规则 `@@` ，如 `@@*.example.com/*` 满足 `@@` 后规则的地址不使用代理\n4. 匹配地址开始和结尾 `|` ，如 `|http://example.com` 、 `example.com|` 分别表示以 `http://example.com` 开始和以 `example.com` 结束的地址\n5. `||` 标记，如 `||example.com` 则 `http://example.com https://example.com ftp://example.com` 等地址均满足条件\n6. 注释 `!` 如 `! Comment`\n\n配置自定义规则时需谨慎，尽量避免与gfwlist产生冲突，或将一些本不需要代理的网址添加到代理列表\n\n规则优先级从高到底为: user-rule \u003e user-rule-from \u003e gfwlist\n\n## FAQ\n\n1. 出现`fetch gfwlist fail.`错误\n\n   gfwlist是在线获取，某些情况下可能被和谐或其它原因导致获取失败，可以通过以下几种方法解决该问题：\n   * 使用`--proxy`参数，通过代理获取gfwlist\n   * 通过其它方式下载到本地，再通过`--gfwlist-local`加载\n   * 使用参数`--gfwlist-url=-`不进行在线获取，这种情况下你只能使用自定义规则\n\n1. gfwlist获取代理使用失败\n\n   * 检查--proxy参数或配置proxy值是格式否符合`PROTOCOL://HOST:POST`，如`socks5://127.0.0.1:1080、http://127.0.0.1:8080`\n   * OSX Linux如果存在http_proxy、https_proxy环境变量，代理可能无法正常使用\n\n1. PAC格式中，参数`--pac-precise`的精确匹配模式的作用是什么？\n\n   1.4.0之后生成的PAC文件默认只对域名进行匹配，如规则`.ftchinese.com/channel/video`处理后为`ftchinese.com`，所有在`ftchinese.com`下的网址都将通过匹配，在这种模式下可以减少PAC文件尺寸，并在一定程度上提高效率，推荐使用，但如果你依然想用原有的规则进行精确的网址匹配判断，则使用参数`--pac-precise`或在配置文件中设置`pac-precise=true`即可。\n\n1. genpac命令未找到\n\n   可能是因为`genpac`命令没有被安装到系统路径，如Ububtu 16.04且通过apt-get安装的pip的环境下，`genpac`执行入口文件被安装到了`~/.local/bin`，遇到这种情况，将`~/.local/bin`添加到系统路径，或卸载重新使用sudo安装，都可以解决问题。\n\n### 示例\n\n```shell\n# 从gfwlist生成代理信息为SOCKS5 127.0.0.1:1080的PAC文件\ngenpac --format=pac --pac-proxy=\"SOCKS5 127.0.0.1:1080; DIRECT\"\n\n# 从~/config.ini读取配置生成\ngenpac --config=~/config.ini\n\n# PAC格式 压缩\ngenpac --format=pac --pac-proxy=\"SOCKS5 127.0.0.1:1080\" --pac-compress\n\n# PAC格式 精确匹配模式\ngenpac --format=pac --pac-proxy=\"SOCKS5 127.0.0.1:1080\" --pac-precise\n\n# PAC格式 自定义规则\ngenpac --format=pac --pac-proxy=\"SOCKS5 127.0.0.1:1080\" --user-rule=\"||example.com\" --user-rule-from=~/user-rule.txt\n\n# PAC格式 多个自定义规则文件\ngenpac --format=pac --pac-proxy=\"SOCKS5 127.0.0.1:1080\" --user-rule=\"||example.com\" --user-rule=\"||example2.com\" --user-rule-from=~/user-rule.txt,~/user-rule2.txt\n\n# PAC格式 使用HTTP代理127.0.0.1:8080获取在线gfwlist文件\ngenpac --format=pac --pac-proxy=\"SOCKS5 127.0.0.1:1080\" --proxy=\"http://127.0.0.1:8080\"\n\n# PAC格式 如果在线gfwlist获取失败使用本地文件，如果在线gfwlist获取成功更新本地gfwlist文件\ngenpac --format=pac --pac-proxy=\"SOCKS5 127.0.0.1:1080\" --gfwlist-local=~/gfwlist.txt --update-gfwlist-local\n\n# PAC格式 忽略gfwlist，仅使用自定义规则\ngenpac --format=pac --pac-proxy=\"SOCKS5 127.0.0.1:1080\" --gfwlist-disabled --user-rule-from=~/user-rule.txt\ngenpac --format=pac --pac-proxy=\"SOCKS5 127.0.0.1:1080\" --gfwlist-url=- --user-rule-from=~/user-rule.txt\n\n# 其它输出格式同样可以使用上述PAC格式中关于gfwlist和自定义规则的参数\n\n# DNSMASQ\ngenpac --format=dnsmasq --dnsmasq-dns=\"127.0.0.1#5353\" --dnsmasq-ipset=\"SET_NAME\"\ngenpac --format=dnsmasq --dnsmasq-dns=\"127.0.0.1#5353\" --dnsmasq-nftset=\"4#inet#TABLE#GFWLIST,6#inet#TABLE#GFWLIST6\"\ngenpac --format=dnsmasq --dnsmasq-nftset=\"4#inet#TABLE#GFWLIST,6#inet#TABLE#GFWLIST6\"\n\n# V2RAY\ngenpac --format=v2ray --v2ray-proxy-tag=\"proxy\"\ngenpac --format=v2ray --v2ray-proxy-tag=\"proxy\" --v2ray-direct-tag=\"direct\"\ngenpac --format=v2ray --v2ray-proxy-tag=\"proxy\" --v2ray-format=\"yaml\"\n\n# IP\ngenpac --format=ip --ip-cc=\"cn\" --ip-family=\"all\"\ngenpac --format=ip --ip-cc=\"us\" --ip-family=\"6\"\n\n# Shadowrocket\ngenpac --format=shadowrocket --shadowrocket-policy=\"PROXY\"\n\n# Surge\ngenpac --format=surge --surge-policy=\"PROXY\"\n\n# ...\n```\n\n[gfwlist]:                  https://github.com/gfwlist/gfwlist\n[example/config.ini]:        https://github.com/JinnLynn/genpac/blob/master/example/config.ini\n[example/user-rules.txt]:    https://github.com/JinnLynn/genpac/blob/master/example/user-rules.txt\n[example/server/config.ini]: https://github.com/JinnLynn/genpac/blob/master/example/server/config.ini\n[pypi]:             https://pypi.python.org/pypi/genpac\n[pypi-version]:     https://img.shields.io/pypi/v/genpac\n[pypi-license]:     https://img.shields.io/pypi/l/genpac\n[pypi-pyversions]:  https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fgithub.com%2FJinnLynn%2Fgenpac%2Fraw%2Fmaster%2Fpyproject.toml\n\n[dev-version]:      https://img.shields.io/badge/dynamic/toml?url=https%3A%2F%2Fgithub.com%2FJinnLynn%2Fgenpac%2Fraw%2Fdev%2Fpyproject.toml\u0026query=%24.project.version\u0026style=flat\u0026label=dev\u0026prefix=v\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJinnLynn%2Fgenpac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJinnLynn%2Fgenpac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJinnLynn%2Fgenpac/lists"}