代理 – Pac文件 – ipv6与myAdresse()?

我tryig为我的Squid做一个代理pac文件。 我想改变redirect,如果用户在我的networking,或者如果他在家里,例如,我试图让它与myAdress()函数。

我已经testing了这个PAC,我们可以在PAC中使用它的大部分function: http : //findproxyforurl.com/debug-pac-file/ 。

function FindProxyForURL(url, host) { debugPAC ="PAC Debug Information\n"; debugPAC +="-----------------------------------\n"; debugPAC +="Machine IP: " + myIpAddress() + "\n"; <-----| debugPAC +="Hostname: " + host + "\n"; if (isResolvable(host)) {resolvableHost = "True"} else {resolvableHost = "False"}; debugPAC +="Host Resolvable: " + resolvableHost + "\n"; debugPAC +="Hostname IP: " + dnsResolve(host) + "\n"; if (isPlainHostName(host)) {plainHost = "True"} else {plainHost = "False"}; debugPAC +="Plain Hostname: " + plainHost + "\n"; debugPAC +="Domain Levels: " + dnsDomainLevels(host) + "\n"; debugPAC +="URL: " + url + "\n"; // Protocol can only be determined by reading the entire URL. if (url.substring(0,5)=="http:") {protocol="HTTP";} else if (url.substring(0,6)=="https:") {protocol="HTTPS";} else if (url.substring(0,4)=="ftp:") {protocol="FTP";} else {protocol="Unknown";} debugPAC +="Protocol: " + protocol + "\n"; // Reduce volume of alerts to a useable level, eg only alert on static text pages. if (!shExpMatch(url,"*.(js|xml|ico|gif|png|jpg|jpeg|css|swf)*")) {alert(debugPAC);} return "DIRECT"; } 

但在输出上,我有ipv​​6地址?!

 PAC-alert: PAC Debug Information ----------------------------------- Machine IP: fe80::xxx:xxx:xxxx:xxxx <-----| Hostname: download.cdn.mozilla.net Host Resolvable: True Hostname IP: 93.184.221.133 Plain Hostname: False Domain Levels: 3 URL: http://download.cdn.mozilla.net/pub/firefox/releases/37.0.2/update/win32/fr/firefox-37.0.2.complete.mar Protocol: HTTP 

这是正常的吗? 或者有另一种获取用户的ipv4地址的方法? 如果是这样,我不能做这样的testing:

 if ( isInNet(myAddress, "10.0.0.0","255.0.0.0") ) ? 

谢谢你的帮助

myIpAddress函数基于主机只有一个地址的假设。 这从来都不是一个有效的假设。

一个更好的select是返回一个IP地址列表的函数。 看来微软已经推出了自己的扩展 。

myIpAddress返回提供最有用信息的地址是有意义的。 但是你不能依靠这个。 有一些关于myIpAddress报告有时候会返回127.0.0.1 ,这是最没用的。

在你的情况下,它显然没有做出最佳的select,因为链接本地地址包含PAC脚本的有用信息比本地或全球地址要less。 我猜测,在你的情况下,主机确实至less有一个本地或全球地址,它可能会返回。

总的来说,我最好的build议是编写FindProxyForURL ,使其不需要知道主机的IP地址(或者通过服务器端脚本将服务器的PAC服务器的IP地址embedded到脚本中)。

如果您的用户中有相当一部分用户运行支持Microsoft 扩展的浏览器,则还可以添加FindProxyForURLEx函数,该函数利用myIPAddressEx

在PAC脚本中使用dnsResolve也是不可取的, dnsResolve在DNSparsing发生时可能会阻塞浏览器。