[轉(zhuǎn)載]Windows7/10/11 Pac代理腳本及配置

Windows7/10/11 Pac代理腳本及配置

代理自動(dòng)配置(PAC)文件是一個(gè) JavaScript 腳本,其核心是一個(gè) JavaScript 函數(shù),用來決定網(wǎng)頁(yè)瀏覽請(qǐng)求(HTTP、HTTPS,和 FTP)應(yīng)當(dāng)直連目標(biāo)地址,還是被轉(zhuǎn)發(fā)給一個(gè)網(wǎng)頁(yè)代理服務(wù)器并通過代理連接。

一、Pac腳本編寫

以下配置保存到文件,擴(kuò)展名為pac

function FindProxyForURL(url, host) {
var proxy1 = "PROXY 192.168.6.6:6666";
var proxy2 = "PROXY 222.22.66.222:6666";

//本地地址直接連接
if (isPlainHostName(host)) {
    return "DIRECT";
}
// 代理1
if (shExpMatch(url, "*baidu.com*")) {
    return proxy1;
}
// 代理2
if (shExpMatch(url, "*csdn.com*")) {
   return proxy2;
}
return "DIRECT";

}

二、Windows配置

1.界面配置


image.png

2.命令配置

以下配置保存到文件執(zhí)行,擴(kuò)展名為bat,windows的dos命令

@echo off
color 0a
title Use autoconfig script
echo Starting......
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections" /v DefaultConnectionSettings /t REG_BINARY /d 46000000020000000900 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections" /v SavedLegacySettings /t REG_BINARY /d 46000000020000000900 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v AutoConfigURL /d "http://域名/pac/proxy.pac" /f
echo End
@echo off

三、注意事項(xiàng)

pac腳本中盡量不要寫注釋(在某些操作系統(tǒng)版本,導(dǎo)致腳本不能正確加載)
不支持 ftp:// 或 file:// 協(xié)議(Win10)
https不生效(IE、Chrome)
不支持 ftp:// 或 file:// 協(xié)議(Win10)

出現(xiàn)此問題的原因是基于 Windows 10 的計(jì)算機(jī)上的 Internet Explorer 和 Microsoft Edge 使用 WinHttp 代理服務(wù)來檢索代理服務(wù)器信息。 WinHttp 代理服務(wù)不支持對(duì) PAC 文件使用 ftp:// 或 file:// 協(xié)議。
原文地址:
https://learn.microsoft.com/zh-cn/troubleshoot/developer/browsers/administration/cannot-read-pac-file

https不生效(IE、Chrome)
1.IE瀏覽器

可以修改注冊(cè)表配置后支持(需要重啟系統(tǒng))

配置內(nèi)容

以下配置保存到文件執(zhí)行,擴(kuò)展名為reg,注冊(cè)表命令

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings]
"EnableAutoproxyResultCache"=0

原文地址:
https://support.microsoft.com/en-us/topic/how-to-disable-automatic-proxy-caching-in-internet-explorer-92735c9c-8a26-d0d8-7f8a-1b46595cbaba

部分原文:

HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings

Value: EnableAutoproxyResultCache
Type: REG_DWORD
Data value: 0 = disable caching; 1 (or key not present) = enable automatic proxy caching (this is the default behavior)If the registry key is not present, you can create the registry key by using the following registry file:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings]"EnableAutoProxyResultCache"=dword:00000000"

2.Google瀏覽器

不支持
原文地址:
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_PAC_file

image.png

參考資料
1.代理自動(dòng)配置文件(PAC)文件
2.Windows 10不讀取文件協(xié)議引用的 PAC 文件

Windows7/10/11 Pac代理腳本及配置_pac腳本-CSDN博客

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容