firefox proxy settings via command line

2019-01-11 00:42发布

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

Thanks

17条回答
在下西门庆
2楼-- · 2019-01-11 01:04

for the latest firefox you must change

cd *.default

to

cd *.default*
查看更多
Rolldiameter
3楼-- · 2019-01-11 01:07
it working perfect.

cd /D "%APPDATA%\Mozilla\Firefox\Profiles"
cd *.default
set ffile=%cd%
echo user_pref("network.proxy.ftp", "YOUR_PROXY_SERVER"); >>prefs.js
echo user_pref("network.proxy.ftp_port", YOUR_PROXY_PORT); >>prefs.js
echo user_pref("network.proxy.http", "YOUR_PROXY_SERVER"); >>prefs.js
echo user_pref("network.proxy.http_port", YOUR_PROXY_PORT); >>prefs.js
echo user_pref("network.proxy.share_proxy_settings", true); >>prefs.js
echo user_pref("network.proxy.socks", "YOUR_PROXY_SERVER"); >>prefs.js
echo user_pref("network.proxy.socks_port", YOUR_PROXY_PORT); >>prefs.js
echo user_pref("network.proxy.ssl", "YOUR_PROXY_SERVER"); >>prefs.js
echo user_pref("network.proxy.ssl_port", YOUR_PROXY_PORT); >>prefs.js
echo user_pref("network.proxy.type", 1); >>prefs.js
set ffile=
cd %windir%
查看更多
兄弟一词,经得起流年.
4楼-- · 2019-01-11 01:07

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

查看更多
Animai°情兽
5楼-- · 2019-01-11 01:08

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

查看更多
孤傲高冷的网名
6楼-- · 2019-01-11 01:10

I don't think you can. What you can do, however, is create different profiles for each proxy setting, and use the following command to switch between profiles when running Firefox:

firefox -no-remote -P <profilename>
查看更多
贼婆χ
7楼-- · 2019-01-11 01:14

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.

查看更多
登录 后发表回答