gpt4 book ai didi

Linux 上的 Python Socket 编程 - Errno 19 : No such device

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:55:30 26 4
gpt4 key购买 nike

我有个小问题。在调试这段代码时:

s=socket(AF_PACKET, SOCK_RAW, IPPROTO_IP)
try:
host=gethostbyname(gethostname())
s.bind((host, 0))

subprocess.check_call(['ifconfig', 'eth0', 'promisc'])

我收到错误 [Errno 19] No such device,同时调用行 s.bind((host, 0))

最佳答案

由于您使用的是原始套接字,因此应相应地调整 bind 的参数。请参阅以下来自 socket.bind

的 hep 片段
bind(...) unbound socket._socketobject method
bind(address)

Bind the socket to a local address. For IP sockets, the address is a
pair (host, port); the host must refer to the local host. For raw packet
sockets the address is a tuple (ifname, proto [,pkttype [,hatype]])

我猜 s.bind(('eth0', N)) 应该适合你。您需要阅读有关如何为 N 选择正确值的信息。

关于Linux 上的 Python Socket 编程 - Errno 19 : No such device,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26441492/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com