0

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";
        }
    }   
}
m02ph3u5
  • 3,022
  • 7
  • 38
  • 51
logan_92
  • 117
  • 9
  • Please provide all the relevant code. You don't use `str.match` anywhere in your code. – Unmitigated Jun 30 '20 at 14:52
  • this is the whole code – logan_92 Jun 30 '20 at 15:16
  • Where do you use `str.match` then? – Unmitigated Jun 30 '20 at 15:16
  • i use this link https://app.thorsen.pm/proxyforurl to test PAC file but it comes with this error TypeError: str.match is not a function.i don't use str.match in my code – logan_92 Jun 30 '20 at 15:17
  • when i replace resolved_ip with host shExpMatch(host, "10.*") , it will work but this will lead of a lot of dns queries from PC – logan_92 Jun 30 '20 at 15:18
  • resolved_ip is working with isInNet but it doesn't work with shExpMatch() var resolved_ip = dnsResolve(host); if (isInNet(resolved_ip, "10.0.0.0", "255.0.0.0") || isInNet(resolved_ip, "10.0.0.0", "255.0.0.0")) – logan_92 Jun 30 '20 at 15:24

0 Answers0