gwlist转foxyproxy实用小程序
企业开发
2023-04-17 07:49:52
阅读次数: 0
下载及转码
- 首先下载那个文件,具体不多说,源文件是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))
{
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())
{
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插件,点 “选项” > “模式” ,然后点击左下角的 “导入模式” 即可。
- 规则采用白名单模式,即列表中的网站走特殊通道,其他全部走直连通道,这种模式优点是几乎不妨碍正常上网,缺点是特殊网站列表可能不全,有时候需要自己手动添加。
转载自blog.csdn.net/rockage/article/details/129891964