Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
547 views
in Technique[技术] by (71.8m points)

firefox - How to discover de proxy used in a pac

In FireFox internet connection is made through a proxy auto config file "something.pac"

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

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.

Edit:

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.

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.

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.

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.

Per the Microsoft documentation for isInNet():

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).

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 }

Hope that helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...