How to intercept and proxy all (or specified) traffic from a specified process

problem description

how to intercept and proxy all (or specified) traffic from a specified process (giving priority to Windows), so that traffic from a specified program, rather than global traffic, passes through VPN.

the environmental background of the problems and what methods you have tried

there are some websites in our school that need to be linked to VPN to access, but every time we connect to VPN, the traffic of all applications will go. VPN, not only takes up the bandwidth of VPN, but also has a high delay. Therefore, want to write their own Mini Program to solve this problem, or have off-the-shelf software is also excellent.

I have tried to change the routing table, but the applicability is very poor. You have to know in advance the destination address of the traffic to pass through the VPN, and then add it to the routing table one by one. If the address is dynamic and there are a lot of addresses, it would be impractical to add them manually.

desired results

if there is no off-the-shelf software, I would like to know the relevant system call or other functions that can be implemented by myself, such as getting all connections of a process, proxy-specified connections, and forwarding data through VPN. If possible, I would like to use Node.js to implement this function.


this requirement is much easier to implement on Linux than on Windows. Here's a brief introduction to the idea, hoping to have some reference

. < H2 > Linux < / H2 >

set up a separate network stack using network namespace, start VPN and set it as the default route, and finally move the processes that need VPN to the network namespace.

< H2 > Windows < / H2 >

there are many ways, one of which is relatively easy to implement.

  1. first convert VPN to socket proxy.
  2. the key method to hijack the ws2_32.dll of the target process by injecting DLL and so on.
    for example, getaddrinfo, connect, send, recv and so on.
  3. forwards hijacked traffic to the socket proxy.

you may not be able to do this if you need to call Windows API, pure node.js, but you can try node.js 's Windows API module.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e46a68-436ab.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e46a68-436ab.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?