1
2
3
4
5
6
7
8
9
10
11
12
13
14
import socket
import requests
from requests_toolbelt.adapters.socket_options import SocketOptionsAdapter


session = requests.Session()
# set interface here
options = [(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, b"eth0")]
for prefix in ('http://', 'https://'):
session.mount(prefix, SocketOptionsAdapter(socket_options=options))


print(session.get("https://test.ipw.cn/").text)

16936361955351693636194706.png