Finding the proxy setting for Firefox from a command line

Malwarebytes Anti-Malware
For Firefox on a Microsoft Windows system, one can obtain the proxy settings within Firefox by using the Alt-T key combination to bring up the Tools menu then selecting Options, then Settings under the Network tab to see the Connection Settings. Below is shown an example of a SOCKS proxy beng used. The proxy settings are stored within the prefs.js file within the user's Firefox profile directory.

Firefox proxy settings - SOCKS proxy

The Firefox profile directory can be found beneath the code APPDATA directory for a user. You can obtain the directory path for APPDATA by the command echo %APPDATA%. E.g., supposing the user's account is named Joe and the command is run from that account, you might see the following:

C:\>echo %APPDATA%

If you append Mozilla\Firefox\Profiles to that directory, you can see the default profile directory for the account.

C:\> dir "%APPDATA%\Mozilla\Firefox\Profiles"
 Volume in drive C is TI10666640G
 Volume Serial Number is 0E19-9292

 Directory of C:\Users\Joe\AppData\Roaming\Mozilla\Firefox\Profiles

01/02/2014  12:11 PM    <DIR>
01/02/2014  12:11 PM    <DIR>
11/15/2014  05:59 PM    <DIR>          nqp8058j.default
               0 File(s)              0 bytes
               3 Dir(s)  242,344,960,000 bytes free

The name of the directory will vary, i.e., there will be 8 characters followed by a period then "default", but the first 8 characters will vary.

If you wanted to use a script that displayed just the name of the default profile directory and not all of the extraneous information, the following could be placed in a batch file, e.g., show-firefox-proxy-setting.bat:

@echo off
set ffdir=%APPDATA%\Mozilla\Firefox\Profiles
FOR /F "tokens=5" %%G IN ('dir %ffdir% ^| find /i "default"') DO echo %%G

The first line @echo turns off the display of the lines in the batch file when it is executed. The next line sets the variable ffdir to the value of %APPDATA%\Mozilla\Firefox\Profiles . To get just the line I'm interested in, i.e., the one containing nqp8058i.default, I need to use a FOR loop. The /F indicates I want to include an option on the line, in this case "tokens=5", since I'm not interested in every item on the line, e.g., I'm not interested in the time stamp for the file, just the 5th element on the line, which is the directory name. I want two commands to be executed in the FOR loop. The first one will be the dir command, which will display the results of dir %ffdir%. If I've already set the value of the variable ffdir, I would get something like the following:

C:\>dir %ffdir%
 Volume in drive C is TI10666640G
 Volume Serial Number is 0E19-9292

 Directory of C:\Users\Jim\AppData\Roaming\Mozilla\Firefox\Profiles

01/02/2014  12:11 PM    <DIR>          .
01/02/2014  12:11 PM    <DIR>          ..
11/15/2014  05:59 PM    <DIR>          nqp8058j.default
               0 File(s)              0 bytes
               3 Dir(s)  242,344,075,264 bytes free

So I need to pipe the output of the dir command into the find command. But if I use 'dir %ffdir% | find /i "default"', it won't work and I'll get an error message, because the pipe symbol, |, has a special meaning to Windows requiring me to put an "escape character" before it. For Microsoft Windows batch files, that escape character is the caret symbol, ^. If I use FOR /F "tokens=5" %%G IN ('dir %ffdir% ^| find /i "default"') DO echo %% , I'll get the output I want.


The proxy settings are stored in that directory in a file prefs.js . So I'll change the FOR loop line and append the directory name I've just obtained to the contents of ffdir and then stick prefs.js at the end of the contents of the variable.

@echo off
set ffdir=%APPDATA%\Mozilla\Firefox\Profiles
FOR /F "tokens=5" %%G IN ('dir %ffdir% ^| find /i "default"') DO set prefdir=%%G
set prefdir=%ffdir%\%newdir%
echo %prefdir%

I would then see the following when I run the batch file


Now to find the proxy setting I need to search for "network.proxy" within that file, which I can do by modifying the batch file to contain the following lines:

@echo off
set ffdir=%APPDATA%\Mozilla\Firefox\Profiles
FOR /F "tokens=5" %%G IN ('dir %ffdir% ^| find /i "default"') DO set prefdir=%%G
set preffile=%ffdir%\%prefdir%\prefs.js
find /i "network.proxy" %preffile%

Then when I run the batch file, if Firefox for the user is set to use a SOCKS proxy running on the localhost address,, with the default SOCKS proxy port of 1080, I see the following output:


user_pref("network.proxy.socks", "");
user_pref("network.proxy.socks_port", 1080);
user_pref("network.proxy.type", 1);

The IP address of the SOCKS proxy is the localhost, aka local loopback address,, because Firefox is set to use a SOCKS proxy set up through an SSH tunnel to another system in this case. However, if the configuration of Firefox was set to "no proxy", the only thing in the output that would change would be the value for network.proxy.type , which would change from 1 when Firefox is configured to use a "Manual proxy configuration" for a "SOCKS Host" to 0 when it is configured for "No proxy".

The values for network.proxy.type correspond to the following settings in Firefox:

0No proxy
1Manual proxy configuration
4Auto-detect proxy settings for this network

If "use system proxy settings" is selected, there will be no line displayed for network.proxy.type, if you search prefs.js for "nework.proxy".

If I check from another account that is configured to "use system proxy settings", I see the following, i.e., no results:

C:\Users\Administrator>find /i "network.proxy" %APPDATA%\Mozilla\Firefox\Profile





  1. FOR /F
    Command line reference - Web, Database and OS scripting
  2. DOS batch script with for loop and pipe
    Date: May 17, 2011
  3. firefox proxy settings via command line
    Date: May 9, 2009


TechRabbit ad 300x250

Justdeals Daily Electronics Deals1x1 px

Valid HTML 4.01 Transitional

Created: Saturday November 15, 2014