Windows 10上的Python套接字问题

问题描述 投票:0回答:1

我正在尝试在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数据包

python windows sockets networking sniffer
1个回答
0
投票
找到了根本原因:socket.gethostbyname()返回以太网适配器的IP(我不使用它,但是在系统更新后它将变为活动状态)。因此,禁用它可以解决问题。
© www.soinside.com 2019 - 2024. All rights reserved.