Home > Back-end >  How could I redirect HTTP requests to localhost within my own computer through a script or program?
How could I redirect HTTP requests to localhost within my own computer through a script or program?

Time:04-25

I apologize if I simply could not Google the right things to get this answer.

Similar to how one could use a Fiddler script to redirect outgoing requests to a different URL (example below), I would like to redirect outgoing requests to certain URLs to localhost or another URL.

    var list = [ "https://onetoredirect.com", "https://twotoredirect.com" ]

    static function OnBeforeRequest(oS: Session) {
        if(oS.uriContains("http://URLIWantToFullyBlock.com/")){
            oS.oRequest.FailSession(404, "Blocked", "");
        }
        for(var i = 0; i < 2;i  ) {
            if(oS.uriContains(list[i])) {
                oS.fullUrl = oS.fullUrl.Replace("http://", "https://");
                oS.host = "localhost"; // This can also be replaced with another IP address.
                break;
            }
        }
    }

Problem is that I need to do this for a program that I do not have access to, so I cannot just edit the program to send to these new URLs. The two vague ideas I had were

  1. A script/program that runs system-wide and redirects the requests
  2. A script/program that watches my specific process (I have the ability to launch the process programmatically if need be) for these requests and redirects them

Either is viable, obviously I would prefer doing whichever is easier or more versatile lol.

I want to write this as part of a launcher for a game, where you can either use my launcher which would launch the game with the redirection on, or launch the game normally and have the redirection off (to play normally), essentially removing any need for user modification. It is also okay for the solution to be Windows only since the game is Windows only at the moment!

Thank you anyone and everyone for any help <3

CodePudding user response:

I ended up setting up a proxy with mitmproxy with a custom script, then setting the Windows proxy settings to go through localhost automatically!

  • Related