firefox proxy settings via command line

后端 未结 19 1701
闹比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:59

    for the latest firefox you must change

    cd *.default
    

    to

    cd *.default*
    
    0 讨论(0)
  • 2020-12-02 19:01

    cd /D "%APPDATA%\Mozilla\Firefox\Profiles" cd *.default set ffile=%cd% echo user_pref("network.proxy.http", "%1");>>"%ffile%\prefs.js" echo user_pref("network.proxy.http_port", 3128);>>"%ffile%\prefs.js" echo user_pref("network.proxy.type", 1);>>"%ffile%\prefs.js" set ffile= cd %windir%

    This is nice ! Thanks for writing this. I needed this exact piece of code for Windows. My goal was to do this by learning to do it with Linux first and then learn the Windows shell which I was not happy about having to do so you saved me some time!

    My Linux version is at the bottom of this post. I've been experimenting with which file to insert the prefs into. It seems picky. First I tried in ~/.mozilla/firefox/*.default/prefs.js but it didn't load very well. The about:config screen never showed my changes. Currently I've been trying to edit the actual Firefox defaults file. If someone has the knowledge off the top of their head could they rewrite the Windows code to only add the lines if they're not already in there? I have no idead how to do sed/awk stuff in Windows without installing Cygwin first.

    The only change I was able to make to the Windows scripts is above in the quoted part. I change the IP to %1 so when you call the script from the command line you can give it an option instead of having to change the file.

    #!/bin/bash
    version="`firefox -v | awk '{print substr($3,1,3)}'`"
    echo $version " is the version."
    # Insert an ip into firefox for the proxy if there isn't one
    if
    ! grep network.proxy.http /etc/firefox-$version/pref/firefox.js 
      then echo 'pref("network.proxy.http", "'"$1"'")";' >> /etc/firefox-$version/pref/firefox.js 
    fi
    
    # Even if there is change it to what we want
    sed -i s/^.*network.proxy.http\".*$/'pref("network.proxy.http", "'"$1"')";'/  /etc/firefox-$version/pref/firefox.js 
    
    # Set the port
    if ! grep network.proxy.http_port /etc/firefox-$version/pref/firefox.js 
      then echo 'pref("network.proxy.http_port", 9980);' >> /etc/firefox-$version/pref/firefox.js 
      else sed -i s/^.*network.proxy.http_port.*$/'pref("network.proxy.http_port", 9980);'/ /etc/firefox-$version/pref/firefox.js 
    fi
    
    # Turn on the proxy
    if ! grep network.proxy.type  /etc/firefox-$version/pref/firefox.js 
      then echo 'pref("network.proxy.type", 1);' >> /etc/firefox-$version/pref/firefox.js 
      else sed -i s/^.*network.proxy.type.*$/'pref("network.proxy.type", 1)";'/ /etc/firefox-$version/pref/firefox.js 
    fi
    
    0 讨论(0)
  • 2020-12-02 19:02

    user.js is better for customizations as you can include only the lines you want to manipulate, i.e. instead of find-replace you can just overwrite the entire file. Also, prefs.js (at least on Firefox 65.0.1 for Mac) starts with a warning:

    // DO NOT EDIT THIS FILE.
    //
    // If you make changes to this file while the application is running,
    // the changes will be overwritten when the application exits.
    //
    // To change a preference value, you can either:
    // - modify it via the UI (e.g. via about:config in the browser); or
    // - set it within a user.js file in your profile.
    

    In my case, user.js didn't exist, so I created it and included the line to switch between "No proxy" and "Manual proxy configuration" (I'm using only one SOCKS proxy all the time, so no need to change port number or any other details, just flip 0 to 1 in the following line):

    user_pref("network.proxy.type", 1);

    I ended up with a bash script that I placed at /usr/local/bin/firefox:

    #!/bin/bash
    if [ $# -eq 0 ]; then
      echo 'user_pref("network.proxy.type", 0);' > ~/Library/Application\ Support/Firefox/Profiles/t5rvw47o.default/user.js
      open -a Firefox
    else
      case $1 in
        vpn)
          echo 'user_pref("network.proxy.type", 1);' > ~/Library/Application\ Support/Firefox/Profiles/t5rvw47o.default/user.js
          open -a Firefox
      esac 
    fi
    

    To use it, I make sure no Firefox is running and then run firefox to have a straight connection and firefox vpn to use proxy.

    0 讨论(0)
  • 2020-12-02 19:02

    Hello I got the Perfect cod use this code

    cd /D "%APPDATA%\Mozilla\Firefox\Profiles"

    cd *.default

    set ffile=%cd%

    echo user_pref("network.proxy.http", "127.0.0.1"); >>prefs.js

    echo user_pref("network.proxy.http_port", 8080); >>prefs.js

    set ffile=

    cd %windir

    0 讨论(0)
  • 2020-12-02 19:03

    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>
    
    0 讨论(0)
  • 2020-12-02 19:03
    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%
    
    0 讨论(0)
提交回复
热议问题