views:

34

answers:

3

I want to set something up on my computer where if something (program, browser, whatever) makes a request (to a certain domain, I guess) I can send my own response to the request. I once saw a program that did that, and I was wondering how it did it. How would it be done?

+1  A: 

You can build a HTTP proxy that will intercept all requests from the browser. But you have to configure the browser to use the proxy.

mikerobi
Could you install a proxy on the router, to intercept all traffic?
Christian Mann
@Christian Mann, if your router is a computer or some other programmable hardware, then this is a possibility.
mikerobi
A: 

What mikerobi said, but you can also set up your computer or gateway machine to act as a transparent proxy. (You need this if you either don't want to configure your browser, or you're working with an application that uses HTTP but doesn't allow for configuration of a proxy.)

On a FreeBSD or Linux machine (I'm sure there are other OSes that can do this; I mention the ones I use), you can set up your own firewall rules to intercept particular traffic (say, all port 80 traffic, or all port 80 traffic to a particular domain, or whatever) and forward the traffic to your own special proxy, which can return whatever you want.

Frank Shearar
+2  A: 

How about just editing hosts file? Popular operating systems have it. Just use it to redirect to whereever you want. To me it looks like the simplest solution to this question.

AndrejaKo