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()
.
精彩评论