如何从代理自动配置文件中发现使用的代理? [英] How to discover the proxy used from a Proxy Autoconfiguration file?

查看:27
本文介绍了如何从代理自动配置文件中发现使用的代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Firefox 中,互联网连接是通过代理自动配置文件 something.pac 建立的.

In Firefox internet connection is made through a proxy auto configuration file something.pac.

我如何知道某个 URL 正在使用哪个代理服务器?

How do I know for a certain URL which proxy server is being used?

推荐答案

.pac 文件只是一个 ECMAscript - 也就是 JavaScript.查看关于文件格式的维基百科文章.

.pac file is just an ECMAscript - aka JavaScript. Check out the wikipedia article on the file format.

如果您复制 PAC 代码,您可以对其进行处理,以根据目标 url 查看正在使用的代理.如果你觉得花哨,你可以把脚本包装成一个网页(本地),创建一个本地评估的工具.

If you copy the PAC code you can process it to see what proxy is being used based on the target url. If you are feeling fancy, you can wrap the script into a web page (locally) to create a tool to evaluate locally.

作为我开始推荐的方法的替代方法,您可以查看 PACTester,在谷歌代码上可用.这将使您能够快速测试一系列选项.

As an alternative to the method I started recommending, you might check out PACTester, available on Google Code. This will allow you to quickly test a range of options.

如果您有 .Net 并且有兴趣使用 C#,那么您可以查看 MSDN 上的这篇文章,其中包含您可以以与上述类似的方式使用的代码.

If you have .Net available and are interested in playing with C# then you can check out this article on MSDN which has code you can use in a similar fashion to the above.

为了扩展上面概述的原始方法,主机浏览器可能(并且通常是)提供了许多功能.必须在pac 文件中实现的基本功能是FindProxyForUrl().这接受两个参数:url 和主机(从 url 名称派生的主机).提供"的函数包括:isInNet()localHostOrDomainIs()isPlainHostName()isResolvable()

To expand on the original method outlined above, there are a number of functions which may (and typically are) provided by the host browser. The basic function which must be implemented in a pac file is FindProxyForUrl(). This accepts two parameters: the url and the host (the host derived from the name of url). The "provided" functions include: isInNet(), localHostOrDomainIs(), isPlainHostName(), isResolvable(), etc.

如果您在 Microsoft 环境中工作,那么您可以查看此页面在 Technet 上,它通过一些有用的示例描述了 .pac 格式.

If you are working in a Microsoft environment then you can check out this page on Technet which describes the .pac format with some useful examples.

根据 isInNet() 的 Microsoft 文档:

Per the Microsoft documentation for isInNet():

如果主机 IP 地址与指定的 pattern 匹配,isInNet(host, pattern, mask) 函数返回 TRUE.mask 指示要匹配 IP 地址的哪一部分(255=匹配,0=忽略).

The isInNet(host, pattern, mask) function returns TRUE if the host IP address matches the specified pattern. The mask indicates which part of the IP address to match (255=match, 0=ignore).

如果你想了解技术,这里是 用于实现代理自动配置相关服务的 Mozilla 源代码.它将 isInNet() 的 JS 代码指定为:

If you want to get technical, here is the Mozilla source code for the implementation of proxy auto-config related services. It specifies the JS code for isInNet() as:

200 function isInNet(ipaddr, pattern, maskstr) {
201     var test = /^(d{1,3}).(d{1,3}).(d{1,3}).(d{1,3})$/(ipaddr);
202     if (test == null) {
203         ipaddr = dnsResolve(ipaddr);
204         if (ipaddr == null)
205             return false;
206     } else if (test[1] > 255 || test[2] > 255 ||
207                test[3] > 255 || test[4] > 255) {
208         return false;    // not an IP address
209     }
210     var host = convert_addr(ipaddr);
211     var pat  = convert_addr(pattern);
212     var mask = convert_addr(maskstr);
213     return ((host & mask) == (pat & mask));
214     
215 }

希望有帮助!

这篇关于如何从代理自动配置文件中发现使用的代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆