【问题标题】:How to process network flow information in Python to display communicating nodes?如何在 Python 中处理网络流信息以显示通信节点?
【发布时间】:2020-11-08 17:32:39
【问题描述】:

我正在尝试了解如何最好地将通过 JSON 格式的 PacketBeat 收集的网络流可视化为图表,并需要一些建议和建议。

这样做的原因是为了提供一种简单的方法来突出显示我网络上的哪些设备正在与其他设备通信等。

到目前为止,我的想法是处理 PacketBeat JSON,以创建唯一网络节点列表以及以 (source、destination、destination_port) 等格式创建的单独元组列表,以记录谁与谁交谈。

如果我想用“graphviz”Python 库之类的东西生成图形,我不确定上述是否是最好的方法?

如果有任何建议,我将不胜感激。

【问题讨论】:

    标签: python python-3.x diagram


    【解决方案1】:

    是的,pygraphviz 或 gvgen 都可以很好地完成这项任务。 GVGen 在依赖性方面更小,它会生成一个“.dot”文件,然后您将其提供给您通过下载 graphviz 包获得的“dot”命令行工具。 Pygraphviz 可以直接转至 png、svg 等,但在某些电脑上安装会比较困难。

    我已经使用了 pygraphviz 和 gvgen,它们都相当简单并且可以生成我需要的结果。

    但作为一个粗略的例子,使用 gvgen(我今天才使用)你会说:

    import os
    from gvgen import GvGen
    
    graph = GvGen()
    
    sources = ["machineA", "machineB", "machineC"]
    connections = [("machineA", "machineB", "22"), ("machineC", "machineA", "80")]
    
    nodes = {name: graph.newItem(name) for name in sources}
    for source, target, port in connections:
        newlink = graph.newLink(nodes[source], nodes[target])
        graph.propertyAppend(newlink, "label", port)
    
    with open("foo.dot", "w") as outfile:
        graph.dot(outfile)
    
    os.popen(f"dot -Tpng foo.dot -ofoo.png")
    
    

    最近我倾向于 GvGen,因为我上周浪费了半个小时试图让 PyGraphviz 安装在最终用户的计算机上。我花了我的周末用 GvGen 替换 PyGraphviz,我想我将来会这样。如果您只是在自己的计算机上运行它,那么 pygraphviz 很好而且很简单。您将立即知道它是否易于安装。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-03
      • 1970-01-01
      • 1970-01-01
      • 2023-01-10
      • 2012-05-10
      • 2020-12-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多