gwlist转foxyproxy实用小程序

在这里插入图片描述

下载及转码
  • 首先下载那个文件,具体不多说,源文件是base64编码无法直接使用,首先还需要将它转成明文:
    cat encoded_file.txt | base64 --decode > decoded_file.txt
    
  • firefox下最好用的代理切换插件foxproxy,但是这个插件没办法直接使用那个文件,需要将它转换一下(json格式), 话不多说直接放程序:
    #include <iostream>
    #include <fstream>
    #include <regex>
    #include <ctime>
    
    using namespace std;
    
    int main()
    {
    
        ifstream ifs;
        ifs.open("gfwlist_plain.txt", ios::in);
    
        string str, domain, pre_domain, output;
        smatch match;
    
        output = "{\r\n\"whitePatterns\": [\r\n";
    
        while (getline(ifs, str))
        {
            // R "(...)" C++ 11新特性:原始字面量
            regex reg(R"(^(!{0,1}@{0,2}).+?\|?\/?([a-zA-Z0-9_-]+\.)*([a-zA-Z0-9_-]+\.[a-zA-Z0-9]{2,})(?:\.[a-zA-Z0-9]{1,})?\/?.{0,}$)");
    
            bool ret = regex_search(str, match, reg);
    
            if (ret)
            {
                domain = match[2].str() + match[3].str();
    
                if (pre_domain != domain && match[1].str().empty()) // match[1] 忽略 "!"(注释) 或 "@@"(直通网址)
                {
    
                    output = output + R"(
                    {
                        "title": "",
                        "pattern": "*)" +
                             domain +
                             "*\"," +
                             R"(
                        "type": 1,
                        "protocols": 1,
                        "active": true
                    },)";
                }
                pre_domain = domain;
            }
        }
        ifs.close();
    
        output.erase(output.size() - 1); // 删除最后一个逗号,否则无法导入
    
        output = output + R"(
                    ],
                    "blackPatterns": [
                        {
                        "title": "all URLs",
                        "pattern": "*",
                        "type": 1,
                        "protocols": 1,
                        "active": false
                        }
                    ]
                })";
    
        // 写入文件
    
        time_t t = time(nullptr);
        tm *now = localtime(&t);
        int year = now->tm_year + 1900;
        int month = now->tm_mon + 1;
        int day = now->tm_mday;
        string today = to_string(year) + "-" + to_string(month) + "-" + to_string(day);
    
        ofstream ofs("foxyproxy-patterns_" + today + ".json", ofstream::app);
        ofs << output;
        ofs.close();
    
        return 0;
    }
    
    
  • 程序很简单,就是采用正则将源文件中的网站截出来,然后拼接成json格式。运行完毕后程序会生成一个foxproxy的规则文件,打开foxproxy插件,点 “选项” > “模式” ,然后点击左下角的 “导入模式” 即可。
  • 规则采用白名单模式,即列表中的网站走特殊通道,其他全部走直连通道,这种模式优点是几乎不妨碍正常上网,缺点是特殊网站列表可能不全,有时候需要自己手动添加。
  • 在这里插入图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

rockage

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值