我有一点问题。在调试此代码时:
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))
。
答案 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选择正确的值。