There are numerous ways to en- and disable surfing via Privoxy, like any other proxy.

Some, however, might like to always use Privoxy as a proxy and just toggle forwarding to Tor on and off.

For users of UNIXish operating systems there is a script which performs this task.

Windows users had to manually edit Privoxy's config files (or at least I am not aware of a more convenient method).

So I wrote these few lines of code to automate the task. Hopefully this is useful for some of you.

Compile using any D compiler, or use the executable.

/*  tortoggle.d

    a tool to toggle forwarding to tor via privoxy for windows

    written 2007 by Sascha Othman

    These piece of software is in the public domain.
    Permission to use, copy, modify, and distribute this software for any purpose
    and without fee is hereby granted, without any conditions or restrictions.
    This software is provided 'as is' without express or implied warranty.


import std.file;

version(D_Version2) {}
else {
    alias char[] string;

enum Action { enable=1, disable, toggle }

int main(string[] args) {
    int action;
    if (args.length > 1) {
        switch (args[1][0]) {
        case 'e': action=Action.enable; break;
        case 'd': action=Action.disable; break;
        case 't': action=Action.toggle; break;
            return MessageBoxA(null, cast(char*)"command line options:\n\ne[anble]\nd[isable]\nt[oggle on/off]",
                               cast(char*)args[0], MB_OK | MB_ICONEXCLAMATION);;

    char* title=cast(char*)"TorToggle";
    string confile;
    try {
    } catch (Exception e)
        return MessageBoxA(null, cast(char*)e.toString(), title, MB_OK | MB_ICONEXCLAMATION);
    char en='\n', dis='#';
    bool status=false;

    if (!std.file.exists(confile)) return MessageBoxA(null, "Privoxy config not found", title, MB_OK | MB_ICONEXCLAMATION);
    string conf=cast(string);

    int i=std.regexp.find(conf, "forward.*:9050")-1;

    if (i && conf[i]==en) status=true;
    else if (!i || conf[i]!=dis) return MessageBoxA(null, "Unable to detect Tor status", title, MB_OK | MB_ICONEXCLAMATION);

    if (!action) action=MessageBoxA(null, cast(char*)("Tor is "~(status?"en":"dis")~"abled. "~(status?"Dis":"En")~"able?"),
                                title, MB_YESNO | MB_ICONINFORMATION);
    if ( (action==IDYES) || (action==Action.toggle) || ((action!=IDNO) && ((action==Action.enable) ^ status)) ) {
        char[] tmp=conf.dup;
        std.file.write(confile, tmp);
    return 0;
Last modified 8 years ago Last modified on Jun 11, 2011, 3:33:44 PM