myIpAddress() Returns IPv6 Address in Firefox 4 proxy.pac file
I have a proxy.pac file that works fine with IE9 and Chrome under Windows 7 that selects a proxy based on myIpAddress(). It wasn't working in Firefox 4 and it turns out myIpAddress() was returning the IPv6 address of the PC, instead of the IPv4 address. Is there some other function that is guaranteed to return the IPv4 address, or some other setting that would guarantee myIpAddress() returns the IPv4 address? I would rather not remove the IPv6 protocol from the client PC.
Asịsa ahọpụtara
We used the isinnet(myipaddress()) function to determine if a laptop was in the Company network or not, in this way we could tell the browser to use the proxy or not. As an alternative we switched to check if an internal DNS address could be resolved or not.
function FindProxyForURL(url, host)
{
// proxy only needed if in 10.10/16 //if(!isInNet(myIpAddress(), "10.10.0.0", "255.255.0.0")) // return "DIRECT";
// This is now used as the above has issues with ipv6 if(!dnsResolve("name.internal.domain")) return "DIRECT"; // if resolvable use the proxy return "PROXY proxy.internal.domain:8080";
}
Hope this is helpful, as it took a little time to think of this. (with a little help from a colleague)
Gụọ azịza a na nghọta 👍 3All Replies (7)
Never mind, I found a solution. I went into about:config, then set network.dns.disableIPv6 to true. After re-starting Firefox 4, myIpAddress() returns the IPv4 address.
I had a similar problem. After analyzing the issue, I found out, that the myIpAddress() returns the IP address of the first network adapter it will find. The hint to enable network.dns.disableIPv6 does not solve the issue that the "wrong" adapter might be taken. This is especially true when you use dial-up or virtual adapters the connect remotely and need to determine your assigned remote IP. The only way this could be solved is to have myIpAddressEx() implemented. This will return all IP addresses of all adapters. Well you have to write a JavaScript to strip off the "not useful" IPs, but at least you have to chance to find out the local IP (either IPv4 or IPv6).
- )
Edeziri
Asịsa Ahọpụtara
We used the isinnet(myipaddress()) function to determine if a laptop was in the Company network or not, in this way we could tell the browser to use the proxy or not. As an alternative we switched to check if an internal DNS address could be resolved or not.
function FindProxyForURL(url, host)
{
// proxy only needed if in 10.10/16 //if(!isInNet(myIpAddress(), "10.10.0.0", "255.255.0.0")) // return "DIRECT";
// This is now used as the above has issues with ipv6 if(!dnsResolve("name.internal.domain")) return "DIRECT"; // if resolvable use the proxy return "PROXY proxy.internal.domain:8080";
}
Hope this is helpful, as it took a little time to think of this. (with a little help from a colleague)
Thanks! I wasn't even thinking of a solution without using myIpAddress(). This is very clever and eliminates the need for disabling IPv6 in Firefox. I'm wondering if Windows 7 does "negative" DNS caching. Although not a good thing in itself, it would improve the performance of the script when operating outside the internal domain.
As you mention there could be a slow dns response when outside the internal network due to the necessary query. Maybe there is yet another alternative for determining if the browser is in our out of a particular network. In the mean time this seems to be quite browser resillient in that it also works with other browsers. I might revert to the IPv6 address schema in the script as per the other comment once I get my head around IPv6 a bit more as it must be faster.
There are a few known bug reports in bugzilla.mozilla.org about issues with myIpAddress() it can return - 127.0.0.1 - ::1 - IPv6 - ipv4 - the IPv6 local link IP instead of the global one
The function is unsealable und unusable in many cases :-(
@martin_md
You can change your adapter priority so that myIpAddress() returns the IP of the adapter you want
(Win7) go to network and sharing center -> change adapter settings
Press alt, go to advanced -> advanced settings
then change the order of the network adapters in the top field (top adapter has highest priority)
But it would be more helpful if Firefox supported the MyIpAddressEx() function (listing all IP addresses), and made myIpAddress() return an IPv4 address only for compatibility with standard pac/wpad files.
Edeziri