如何在 Windows 8.1(IE11 和现代 UI)上调试 PAC(代理自动配置)?

Jac*_* Ku 12 pac windows-8 windows-8.1

在 Windows 7 + IE10 等较旧的系统上,在 PAC 文件中调用“alert()”会导致显示一个对话框。但是,在 Windows 8.1 中,即使 IE11 似乎在使用 PAC,也不会显示任何对话框。

我目前的情况是 IE11 可以使用 (SOCKS) 代理(由 PAC 返回)就好了,但现代 UI 应用程序与 Internet 完全断开连接。似乎 IE11 和现代 UI 对 PAC 设置的处理方式不同,但我找不到调试它的方法。

总之,我的问题是

  1. 如何在 Windows 8.1 上使用IE11调试 PAC ?
  2. 如何在 Windows 8.1 上使用Modern UI调试 PAC ?

ben*_*tek 5

IE11 PAC 文件更改

Microsoft 对 IE11 处理本地 PAC 文件的方式进行了更改。您可以在此处阅读有关它们的信息,或参阅下文以获取一些快速信息。

另请注意,该alert()语句从 Windows 8 开始不再有效


使用 IE11,不再可能通过文件协议使用 PAC 文件,除非您添加以下注册表项:

[HKLM\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\Internet Settings]
(DWORD)"EnableLegacyAutoProxyFeatures"=1
Run Code Online (Sandbox Code Playgroud)

PAC 文件通过文件协议示例

注意:使用 Windows 8 或更高版本时将不再出现警报语句!


使用 AUTOPROX 调试 PAC 文件下载链接

有时您只需要测试您的 PAC 文件,如果预期的路由返回,尽管您无法访问相关网站。对于此类测试,您可以使用(附加的)命令行实用工具 autoprox.exe,由 Pierre-Louis Coll 创建。

CMD不带附加参数的情况下启动它时,会显示用法:

C:\temp>autoprox
Version : 2.1.0.0
Written by pierrelc@microsoft.com
Usage : AUTOPROX -s  (calling DetectAutoProxyUrl and saving wpad.dat file in temporary file)
Usage : AUTOPROX  [-h] url [Path to autoproxy file]
       -h: calls InternetInitializeAutoProxyDll with helper functions implemented in AUTOPROX
AUTOPROX url: calling DetectAutoProxyUrl and using WPAD.DAT logic to find the proxy for the url
AUTOPROX url path: using the autoproxy file from the path to find proxy for the url
Example: autoprox -s
Example: autoprox http://www.microsoft.com
Example: autoprox -h http://www.microsoft.com c:\inetpub\wwwroot\wpad.dat
Example: autoprox http://www.microsoft.com http://proxy/wpad.dat
Run Code Online (Sandbox Code Playgroud)

这是我们示例的输出:

C:\temp>autoprox http://us.msn.com c:\temp\sample.pac
The Winsock 2.2 dll was found okay
url: http://us.msn.com
autoproxy file path is : c:\temp\sample.pac
Calling InternetInitializeAutoProxyDll with c:\temp\sample.pac
        Calling InternetGetProxyInfo with url http://us.msn.com and host us.msn.com
        Proxy returned for url http://us.msn.com is:
PROXY myproxy:80;
Run Code Online (Sandbox Code Playgroud)

当您想查看调用了哪些 DNS 相关函数时,可以另外使用参数“-h”: 这里是输出,使用时:

C:\temp>autoprox -h http://us.msn.com c:\temp\sample.pac
The Winsock 2.2 dll was found okay
Will call InternetInitializeAutoProxyDll with helper functions
url: http://us.msn.com
autoproxy file path is : c:\temp\sample.pac
Calling InternetInitializeAutoProxyDll with c:\temp\sample.pac
        Calling InternetGetProxyInfo with url http://us.msn.com and host us.msn.com
ResolveHostByName called with lpszHostName: us.msn.com
ResolveHostByName returning lpszIPAddress: 65.55.206.229
        Proxy returned for url http://us.msn.com is:
PROXY myproxy:80;
Run Code Online (Sandbox Code Playgroud)

autoprox.exe 中的错误处理:

  1. 当您指定一个不存在的 PAC 文件(例如命令行中的拼写错误)时,autoprox.exe 的结果将是:

    ERROR: InternetInitializeAutoProxyDll failed with error number 0x6 6.

  2. 当 Pac 文件包含语法错误时,您通常会收到以下显示的消息:

    ERROR: InternetGetProxyInfo failed with error number 0x3eb 1003.

完成本地测试后,应将 PAC 文件复制到 Web 服务器,通过 http 协议访问它。