python - Windows 10 上的 Python 套接字问题
问题描述
我正在尝试在 Windows 10 上捕获数据包。我使用了官方文档页面的说明:
import socket
# the public network interface
HOST = socket.gethostbyname(socket.gethostname())
# create a raw socket and bind it to the public interface
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
s.bind((HOST, 0))
# Include IP headers
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
# receive all packages
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
# receive a package
while True:
print(s.recvfrom(65565))
# disabled promiscuous mode
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)
以前我能够捕捉到它们,但现在我只看到一些虚拟的 UDP 数据包
解决方案
Found the root cause: socket.gethostbyname() returns IP of Ethernet adapter(I don't use such, but it become active after system update). So disabling it fix the issue.
推荐阅读
- mysql - 从两个表中获取结果
- postgresql - Golang 并通过 Ubuntu VPS 中的客户端访问 postgres?
- php - 如何使 PHP StdClass 反射
- javascript - Javascript:在 Wordpress 中为两个特定网页交换标题徽标
- javascript - 如何修复 Django Rest Framework 应用程序中的“禁止”状态代码
- python - 从 Json 数据中提取信息
- linux-kernel - 如何从内核模块读/写 LAPIC 寄存器?
- python - 在不使用 python name.py 和 ./name 的情况下运行 Python 代码
- swift - Swift for TensorFlow `错误:无法查找符号:TensorFlow.Tensor 的类型元数据访问器`
- kdb - 列出不执行自动展开的附加运算符