在 Python 中捕获 Scapy 函数 show_interfaces() 输出

Capturing Scapy function show_interfaces() output in Python

我找到这个link

Capturing Scapy function output in Python

但这对我没有帮助..

show_interfaces() 在 cmd 中运行良好。

但它在控制台中不起作用..

我想得到输出字符串 show_interfaces():

from scapy.arch.windows import show_interfaces
show_interfaces()

你可以看看Scapy的源码, 你会发现 show_interfaces 函数。

def show_interfaces(resolve_mac=True):
    """Print list of available network interfaces"""
    return IFACES.show(resolve_mac)

获取包含接口信息的 python 字典。我用了

IFACES.data

如果需要,您可以从此处将其转换为字符串。