firefox proxy settings via command line

后端 未结 19 1699
闹比i
闹比i 2020-12-02 18:20

How do I change Firefox Proxy settings via command line on windows xp/2k?

Thanks

相关标签:
19条回答
  • 2020-12-02 18:45

    All the other answers here explain how to program your proxy settings into Firefox which is what WPAD was invented to do. If you have WPAD configured then just tell Firefox to use it to auto-detect its settings, as you would in the GUI.

    Connection Settings

    To do this from a cmd file or command line:

    pushd "%APPDATA%\Mozilla\Firefox\Profiles\*.default"
    echo user_pref("network.proxy.type", 4);>>prefs.js
    popd
    

    This of course requires you to have WPAD configured and working correctly. Also I believe prefs.js won't exist until you've run Firefox once.

    0 讨论(0)
  • 2020-12-02 18:49

    The proxy setting is stored in the user's prefs.js file in their Firefox profile.

    The path to the Firefox profile directory and the file is:

    %APPDATA%\Mozilla\Firefox\Profiles\7b9ja6xv.default\prefs.js

    where "7b9ja6xv" is a random string. However, the directory of the default profile always ends in ".default". Most of the time there will be only one profile anyway.

    Setting you are after are named "network.proxy.http" and "network.proxy.http_port".

    Now it depends on what technology you are able/prepared to use to change the file.

    P.S.: If this is about changing the proxy settings of a group of users via the logon script or similar, I recommend looking into the possibility of using the automatic proxy discovery (WPAD) mechanism. You would never have to change proxy configuration on a user machine again.

    0 讨论(0)
  • 2020-12-02 18:49

    The easiest way to do this is to configure your Firefox to use a PAC with a file URL, and then change the file URL from the line command before you start Firefox.

    This is the easiest way. You don't have to write a script that remembers what path to prefs.js is (which might change over time).

    You configure your profile once, and then you edit the external file whenever you want.

    0 讨论(0)
  • 2020-12-02 18:52

    I found a better way to do this with powershell under windows (but really only because I was looking for a way to script changing the user agent string, not muck about with proxies).

    function set-uas
    {
        Param
        (
                [string]$UAS = "Default"
        )
    
        $FirefoxPrefs = "C:\Users\Admin\AppData\Roaming\Mozilla\Firefox\Profiles\*.default\prefs.js"
    
        if ($UAS -eq "Default")
        {
            $fileinfo = type $FirefoxPrefs
            $fileinfo = $fileinfo | findstr /v "general.appname.override"    
            $fileinfo = $fileinfo | findstr /v "general.appversion.override"
            $fileinfo = $fileinfo | findstr /v "general.platform.override"  
            $fileinfo = $fileinfo | findstr /v "general.useragent.appName"  
            $fileinfo = $fileinfo | findstr /v "general.useragent.override" 
            $fileinfo = $fileinfo | findstr /v "general.useragent.vendor"   
            $fileinfo = $fileinfo | findstr /v "general.useragent.vendorSub"
            $fileinfo += "user_pref(`"useragentswitcher.import.overwrite`", false);`n"
            $fileinfo += "user_pref(`"useragentswitcher.menu.hide`", false);`n"
            $fileinfo += "user_pref(`"useragentswitcher.reset.onclose`", false);`n"
            $fileinfo | Out-File -FilePath $FirefoxPrefs -Encoding ASCII
        }
        else
        {
            set-uas Default
        }
    
        if ($UAS -eq "iphone")
        {
            $fileinfo = ""
            $fileinfo += "user_pref(`"general.appname.override`", `"Netscape`");`n"
            $fileinfo += "user_pref(`"general.appversion.override`", `"5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16`");`n"
            $fileinfo += "user_pref(`"general.platform.override`", `"iPhone`");`n"                                                                                                                                      
            $fileinfo += "user_pref(`"general.useragent.appName`", `"Mozilla`");`n"                                                                                                                                     
            $fileinfo += "user_pref(`"general.useragent.override`", `"Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16`");`n"
            $fileinfo += "user_pref(`"general.useragent.vendor`", `"Apple Computer, Inc.`");`n"                                                                                                                         
            $fileinfo += "user_pref(`"general.useragent.vendorSub`", `"`");`n"                                                                                                                                          
            $fileinfo += "user_pref(`"useragentswitcher.reset.onclose`", false);`n"
            $fileinfo | Out-File -FilePath $FirefoxPrefs -Encoding ASCII -Append
        }
        elseif ($UAS -eq "lumia")
        {
            $fileinfo = ""
            $fileinfo += "user_pref(`"general.appname.override`", `"Netscape`");`n"
            $fileinfo += "user_pref(`"general.appversion.override`", `"9.80 (Windows Phone; Opera Mini/9.0.0/37.6652; U; en) Presto/2.12.423 Version/12.16`");`n"
            $fileinfo += "user_pref(`"general.platform.override`", `"Nokia`");`n"                                                                                                                                       
            $fileinfo += "user_pref(`"general.useragent.appName`", `"Mozilla`");`n"                                                                                                                                     
            $fileinfo += "user_pref(`"general.useragent.override`", `"Opera/9.80 (Windows Phone; Opera Mini/9.0.0/37.6652; U; en) Presto/2.12.423 Version/12.16`");`n"
            $fileinfo += "user_pref(`"general.useragent.vendor`", `"Microsoft`");`n"                                                                                                                            
            $fileinfo += "user_pref(`"general.useragent.vendorSub`", `"`");`n"                                                                                                                                          
            $fileinfo += "user_pref(`"useragentswitcher.reset.onclose`", false);`n"
            $fileinfo | Out-File -FilePath $FirefoxPrefs -Encoding ASCII -Append
        }
    }
    

    I have the firefox plugin "useragentswitcher" also installed, and have not tested this without it.
    I also have set "user_pref("useragentswitcher.reset.onclose", false);"

    [EDIT] I've revised my code, it was occasionally outputting some bad character or something. For some reason this is detected by firefox as a corrupt profile, and the entire profile was discarded, and refreshed with a default profile.

    Also, credit where credit is due: this code is loosely based off of what xBoarder posted in his response to sam3344920 (https://stackoverflow.com/a/2509088/5403057). Also, I was able to fix the encoding bug with help from a post from Phoenix14830 (https://stackoverflow.com/a/32080395/5403057)

    [Edit2] Added support for setting the UAS to lumia. This is actually using an Opera mobile UAS, because I still wanted bing to work, and if you use the regular lumia UAS www.bing.com redirects to bing://?%^&* which firefox doesn't know how to process

    0 讨论(0)
  • 2020-12-02 18:57

    I needed to set an additional option to allow SSO passthrough to our intranet site. I added some code to an example above.

    pushd "%APPDATA%\Mozilla\Firefox\Profiles\*.default"
    echo user_pref("network.proxy.type", 4);>>prefs.js
    echo user_pref("network.automatic-ntlm-auth.trusted-uris","site.domain.com, sites.domain.com");>>prefs.js
    popd
    
    0 讨论(0)
  • 2020-12-02 18:58

    I don't think there is a direct way to set the proxy (on Windows).

    You could however install an add-on like FoxyProxy, create several configurations for different proxies and prior to starting FireFox move the appropriate configuration to the correct folder in your FireFox profile (using a batch file).

    0 讨论(0)
提交回复
热议问题