I want to build an application that routes all network traffic (not just HTTP) through my application. Basically, what I want is all the traffic to be given to my application (they should never reach the actual target, my application should handle this), which will in turn be forwarded to a server; same goes for input, just reversed (server -> application -> program which wants an answer). Are there any libraries (or similar stuff) that would make creating the application easier? I'm looking for something that I can use from Python or Java, but if it's really needed, I can learn another language.
If you want to route only tcp traffic is actually kind of simple using threads and sockets.
You should listen in a different port for every server you want to reach. Either in Java or Python you have to create a "socket" for every port you want to listen in.
For every new connection you create a new connection to the server and create two new threads to handle that connection, one thread will be reading everything from the client and sending it to the server. The other will be reading everything from the server and sending it to the client. When any end of the connection closes it, you close the other and end both threads.
Routing all packets through my program?