开发者

routing a only specific traffic through a vpn connection via python

开发者 https://www.devze.com 2023-03-06 20:32 出处:网络
Is there any method to connect to vpn through python and have th开发者_如何学编程at traffic of that application only route through the said VPN?Python itself can\'t be used to route traffic; though yo

Is there any method to connect to vpn through python and have th开发者_如何学编程at traffic of that application only route through the said VPN?


Python itself can't be used to route traffic; though you can use it to execute system commands to change your routing table. If you're on Linux, you need to use the ip command from the iproute2 and iptables from netfilter to change the routing behavior of specific traffic.


Please, be more specific in your question. Generally, yes, it is possible.

If you use python 2.7 or newer, you can use source_address option for http connections (see reference for libraries you use) as tuple ('interface address', port).

If you use sockets in your app, use socket.bind(('interface address', port)) on created socket before socket.connect().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号