I am trying to write a node program (suggestion for other language are welcome) that can parse and run a corporate proxy script PAC and return the appropriate proxy server to use programmatically.
Are there any existing solutions that can do this? (or is this only possible through a browser)
It seems like PAC files assume certain global functions exist in the execution context such as
shExpMatch()
myIpAddress() // interestingly the nodejs ip package return the true LAN DHCP assigned IP instead of a VPN IP
The goal is to resolve the right proxy server each time a shell is launched (or not set it at all if not behind a proxy)
any tip is greatly appreciate it.
If you're sticking with Node, I'd recommend using something like pac-resolver for this.
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));
In any case, you can look at the repo to see which global functions need to be defined and how that would be done in JavaScript.
If you can use other languages, look at pacparser.
The list of standard global functions, by the way, is here: