【发布时间】:2020-11-18 23:06:01
【问题描述】:
我的 Raspberry Pi 上有多个网络接口,它们都具有相同的 IP 地址(192.168.3.1),但命名如下:eth1、eth2 等。
有没有办法通过特定的网络接口发出请求,即使 IP 地址相同?例如,运行eth2。
这是我要运行的代码:
class Modem(object):
BASE_URL = 'http://{host}'
TOKEN_URL = '/api/webserver/SesTokInfo'
session = None
def __init__(self,host='192.168.3.1'):
self.host = host
self.base_url = self.BASE_URL.format(host=host)
self.session = requests.Session()
def switch_modem(self, state='02'):
try:
# Get session and verification tokens from the modem
r = self.session.get(self.base_url + self.TOKEN_URL, timeout=10)
_dict = xmltodict.parse(r.text).get('response', None)
【问题讨论】:
-
你为什么要这样做?我想不出在多个接口上使用相同 IP 的任何正当理由。
标签: python linux python-requests raspberry-pi