node.js 获取系统默认代理设置

如果是linux:

const proxyInfo = process.env.HTTP_PROXY || process.env.HTTPS_PROXY || process.env.ALL_PROXY;

如果是win32,从注册表读取

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings

是否启用,ProxyEnable,

代理设置,ProxyServer,

安装个注册表操作模块:npm install regedit --save

const regedit = require('regedit')
const promisifiedRegedit = require('regedit').promisified;
if (process.platform === "win32") {
   const listResult = await promisifiedRegedit.list('HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings');
   const OneItem=listResult['HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings'];
   const ProxyEnable=OneItem.values['ProxyEnable'].value;
   const ProxyServer=OneItem.values['ProxyServer'].value;
}

就这么简单。

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注