Proxy – Using PAC File with IPv6 and myAdresse()

pacPROXY

I'm tryig to make a proxy pac file for my Squid.
I suppose to change redirection if the user is in my network or if he is at home for example, and I try to make it whith the myAdress() function.

I have test this PAC, whith most of function that we can use in a PAC : 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, e.g. only alert on static text pages.
    if (!shExpMatch(url,"*.(js|xml|ico|gif|png|jpg|jpeg|css|swf)*")) {alert(debugPAC);}

   return "DIRECT";
}

But on the output, I have ipv6 address ?!

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

Is that normal ? Or there another method for getting ipv4 address of the user ?
If so, I can not make test like :

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

Thanks for your help

Best Answer

The myIpAddress function is based on the assumption that a host has only a single address. This has never been a valid assumption.

A better alternative would be a function returning a list of IP addresses. It appears Microsoft has introduced their own extension doing exactly that.

It would make sense for myIpAddress to return the address providing the most useful information. However you cannot rely on that. There are reports about myIpAddress sometimes returning 127.0.0.1 which is mostly useless.

In your case it clearly didn't make an optimal choice either, because a link-local address contains less useful information for a PAC script than a local or global address would. And I am guessing that in your case the host does have at least one local or global address it could be returning instead.

Overall my best recommendation is to write FindProxyForURL such that it doesn't need to know the IP address of the host (or have the server serving the PAC script embed the IP address of the client into the script through server side scripting).

If a significant fraction of your users run a browser with support for Microsoft's extension you can also add a FindProxyForURLEx function, which takes advantage of myIPAddressEx

It is also not advisable to use dnsResolve in a PAC script due to possibly blocking the browser while a DNS resolution is happening.