This is PAC file I'm trying to force users to bypass proxies if the destination is local. If the destination is a public IP it will force users' traffic to be distributed on 2 proxies and if they are down the users' traffic will bypass proxies.
I'm using var resolved_ip = dnsResolve(host)
to optimize the code because the dnsresolve()
takes time so I need to do it once and put result in if condition. I don't want to make 5 dns resolution in worst case to match the if condition. But resolved_ip = dnsResolve(host)
gives me this error.
This code give me an error
TypeError: str.match is not a function.
When I replace resolved_ip
with host
it's working fine.
The output of dnsResolve()
is string https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_(PAC)_file#dnsResolve
also test method compare strings https://www.w3schools.com/jsref/jsref_regexp_test.asp
function FindProxyForURL(url, host) {
var regexpr = /:\/\/172\.[1-3][0-9]\.*/
var regexpr1 = /:\/\/2[23][4-9]\.*/
var resolved_ip = dnsResolve(host);
if (shExpMatch(resolved_ip, "10.*") || shExpMatch(resolved_ip, "192.168.*") || regexpr.test(resolved_ip) || regexpr1.test(resolved_ip))
{
return "DIRECT";
}
else
{
var myip = myIpAddress()
var ipbits = myip.split(".")
var myseg = parseInt(ipbits[3])
if (myseg % 2 == 0) {
return "PROXY p1.company.com:8080; PROXY p2.company.com:8080 DIRECT";
}
else {
return "PROXY p2.company.com:8080; PROXY p1.company.com:8080 DIRECT";
}
}
}