有没有办法使用
pyshark
列出与某个 IP 地址匹配的接口?在 wireshark
中,您可以看到与接口关联的地址。
以下是 Wi-Fi 上使用的地址示例: 我还遇到过这篇 post for
tshark
,其中提到了显示接口的 IP 地址和 MAC 地址的命令。
pyshark
有类似的可能吗,因为它是tshark
的Python包装器?
那个
WireShark
屏幕截图让你的问题不清楚。我不确定您想要过滤哪个 IP address
。
您可以使用 'bpf_filter` 按 IP 地址进行过滤。
源IP地址是这个
src host
目标 IP 地址是这个 dst host
这是有关如何使用此类过滤器的基本示例。
import pyshark
capture = pyshark.LiveCapture(interface='your network interface`, bpf_filter='ip and src host 192.168.86.1')
try:
for packet in capture:
# do something with the packet
except AttributeError as error:
pass
这里是过滤通过我的路由器发送的 DNS 数据包的示例
import pyshark
capture = pyshark.LiveCapture(interface='your network interface', bpf_filter='ip and src host 192.168.86.1', display_filter='dns')
try:
for packet in capture:
# do something with the packet
except AttributeError as error:
pass
这是另一个过滤通过我的路由器发送的 DNS 数据包。
import pyshark
capture = pyshark.LiveCapture(interface='your network interface', bpf_filter='udp port 53 and src host 192.168.86.1')
try:
for packet in capture:
# do something with the packet
except AttributeError as error:
pass
这里是我为 PyShark 开发的一些使用文档,并且已经更新文档大约 4 年了。我将在文档中添加过滤 IP 地址作为示例。