为分支代理配置创建 WPAD 和 PAC 配置文件

为分支代理配置创建 WPAD 和 PAC 配置文件

以下是当前文件的配置proxy.pac

function FindProxyForURL(url, host)
{
var resolved_ip = dnsResolve(host);
if (isInNet(resolved_ip, "10.0.0.0", "255.0.0.0") ||
isInNet(resolved_ip, "172.16.0.0", "255.240.0.0") ||
isInNet(resolved_ip, "192.168.0.0", "255.255.0.0") ||
isInNet(resolved_ip, "127.0.0.0", "255.0.0.0"))
return "DIRECT";
else
   return "PROXY 172.16.51.254:8080";

我们需要在下面进行更改。请帮我解决此问题。

   return "PROXY 172.16.51.254:8080";

我们有许多办公室,并且有不同的代理,因此我们需要为整个网络提供单独的 wpad 文件。

我们不会172.16.51.254在这个文件中进行硬编码。相反,我们需要让 wpad/pac 文件找出代理是什么。它将通过将用户 PC 的第 4 个八位字节替换为 .254 来知道代理地址。

例如:如果您的 PC 地址是172.16.51.83,则代理服务器就是172.16.51.254。如果您的 PC 地址是172.16.8.22,则代理服务器就是172.16.8.254

答案1

您收到过答复吗?

尝试这样的操作:

function FindProxyForURL(url, host) {
// Proxy variables
var PROXY1 = "PROXY 172.16.51.254:8080"
var PROXY2 = "PROXY 172.16.8.254:8080"
var BLACKHOLE = "PROXY 127.0.0.1:8080"  //Deny Internet access by using localhost as proxy
var CLIENTIP = myIpAddress();
var resolved_ip = dnsResolve(host);

if (
    isInNet(resolved_ip, "10.0.0.0", "255.0.0.0") || 
    isInNet(resolved_ip, "172.16.0.0", "255.240.0.0") || 
    isInNet(resolved_ip, "192.168.0.0", "255.255.0.0") || 
    isInNet(resolved_ip, "127.0.0.0", "255.0.0.0")
) 
return "DIRECT";

if (
    isInNet(CLIENTIP,"172.16.51.0","255.255.255.0")  //If CLIENTIP falls in range
)
return PROXY1;  //return specific proxy

if (
    isInNet(CLIENTIP,"172.16.8.0","255.255.255.0")//If CLIENTIP falls in range
)
return PROXY2;  //return specific proxy

return BLACKHOLE; //If all of the above fails return blackhole proxy, e.g. deny internet access

}

相关内容