為了改善您的使用體驗,本網站正在進行維護,部分功能暫時無法使用。若本站的文件無法解決您的問題,想要向社群發問的話,請到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 發問,我們的社群成員將很快會回覆您的疑問。

搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

myIpAddress() Returns IPv6 Address in Firefox 4 proxy.pac file

  • 7 回覆
  • 68 有這個問題
  • 1 次檢視
  • 最近回覆由 Apokalipse

more options

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.

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.

被選擇的解決方法

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)

從原來的回覆中察看解決方案 👍 3

所有回覆 (7)

more options

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.

more options

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

)

由 martin_md 於 修改

more options

選擇的解決方法

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)

more options

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.

more options

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.

more options

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 :-(

more options

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

由 Apokalipse 於 修改