Linux上的Python Socket编程 - Errno 19:没有这样的设备

时间:2014-10-18 15:38:29

标签: python linux sockets

我有一点问题。在调试此代码时:

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))

1 个答案:

答案 0 :(得分:0)

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

中的以下代码段
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选择正确的值。