Node.js 如何在节点中运行PAC代理脚本?
我正在尝试编写一个节点程序(欢迎对其他语言提出建议),该程序可以解析和运行公司代理脚本PAC,并返回适当的代理服务器以编程方式使用 是否有任何现有的解决方案可以做到这一点?(或者这只能通过浏览器实现) 似乎PAC文件假定某些全局函数存在于执行上下文中,例如Node.js 如何在节点中运行PAC代理脚本?,node.js,proxy,http-proxy,Node.js,Proxy,Http Proxy,我正在尝试编写一个节点程序(欢迎对其他语言提出建议),该程序可以解析和运行公司代理脚本PAC,并返回适当的代理服务器以编程方式使用 是否有任何现有的解决方案可以做到这一点?(或者这只能通过浏览器实现) 似乎PAC文件假定某些全局函数存在于执行上下文中,例如 shExpMatch() myIpAddress() // interestingly the nodejs ip package return the true LAN DHCP assigned IP instead of a VPN I
shExpMatch()
myIpAddress() // interestingly the nodejs ip package return the true LAN DHCP assigned IP instead of a VPN IP
目标是在每次启动shell时解析正确的代理服务器(或者如果不在代理后面,则根本不设置代理服务器)
非常感谢任何提示。如果您坚持使用Node,我建议您使用类似的方法
const pac = require('pac-resolver');
const fetch = require('node-fetch');
const ip = require('ip');
fetch('http://<proxy_host>:<proxy_port>')
.then(res => res.text())
.then(body => {
// to handle a bug when pinging 8.8.8.8 will time out
// see: https://github.com/TooTallNate/node-pac-resolver/issues/18
findProxy = pac(body, { sandbox: { myIpAddress: ip.address }, });
return findProxy('http://google.com/'));
})
.then(proxy => console.log(proxy))
.catch(err => console.error(err));
const pac=require('pac-resolver');
const fetch=require('node-fetch');
常数ip=要求('ip');
获取('http://:')
。然后(res=>res.text())
。然后(body=>{
//Ping 8.8.8.8将超时时处理错误
//见:https://github.com/TooTallNate/node-pac-resolver/issues/18
findProxy=pac(body,{sandbox:{myIpAddress:ip.address},});
返回findProxy('http://google.com/'));
})
.then(proxy=>console.log(proxy))
.catch(err=>console.error(err));
在任何情况下,您都可以查看哪些全局函数需要定义,以及如何在JavaScript中定义
如果你能使用其他语言,请看
顺便说一下,标准全局函数的列表是:
- 脱氧核糖核酸
- shExpMatch
- 伊西内特
- 我的地址
- dnsResolve
- isPlainHostName
- 本地旅店
- 是可溶的
- DNS域级别
- 平日范围
- 日期范围
- 时间范围
- 警觉的