Search code examples
javapythonnetwork-programmingtcptunnel

Routing all packets through my program?


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.


Solution

  • What you want to use is a packet capture library, you can use pcap or its implementation or bindings in python or java.

    However things like these are ussually implemented at the low level ideally using C, Here is a tutorial Tutorial

    EDIT: In light of your comments you definitely want to take a look at netfilter hooks

    While you are at it you also might want to take a look at netfilter hooks