1. <small id='mZxgF'></small><noframes id='mZxgF'>

      <legend id='mZxgF'><style id='mZxgF'><dir id='mZxgF'><q id='mZxgF'></q></dir></style></legend>
        <bdo id='mZxgF'></bdo><ul id='mZxgF'></ul>
        <tfoot id='mZxgF'></tfoot>

      1. <i id='mZxgF'><tr id='mZxgF'><dt id='mZxgF'><q id='mZxgF'><span id='mZxgF'><b id='mZxgF'><form id='mZxgF'><ins id='mZxgF'></ins><ul id='mZxgF'></ul><sub id='mZxgF'></sub></form><legend id='mZxgF'></legend><bdo id='mZxgF'><pre id='mZxgF'><center id='mZxgF'></center></pre></bdo></b><th id='mZxgF'></th></span></q></dt></tr></i><div id='mZxgF'><tfoot id='mZxgF'></tfoot><dl id='mZxgF'><fieldset id='mZxgF'></fieldset></dl></div>
      2. 在 python 中处理 tcpdump 输出

        时间:2023-07-21
        <legend id='ydJvC'><style id='ydJvC'><dir id='ydJvC'><q id='ydJvC'></q></dir></style></legend>

            • <bdo id='ydJvC'></bdo><ul id='ydJvC'></ul>

              <small id='ydJvC'></small><noframes id='ydJvC'>

                  <tfoot id='ydJvC'></tfoot>

                1. <i id='ydJvC'><tr id='ydJvC'><dt id='ydJvC'><q id='ydJvC'><span id='ydJvC'><b id='ydJvC'><form id='ydJvC'><ins id='ydJvC'></ins><ul id='ydJvC'></ul><sub id='ydJvC'></sub></form><legend id='ydJvC'></legend><bdo id='ydJvC'><pre id='ydJvC'><center id='ydJvC'></center></pre></bdo></b><th id='ydJvC'></th></span></q></dt></tr></i><div id='ydJvC'><tfoot id='ydJvC'></tfoot><dl id='ydJvC'><fieldset id='ydJvC'></fieldset></dl></div>
                    <tbody id='ydJvC'></tbody>

                  本文介绍了在 python 中处理 tcpdump 输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 python 中处理 tcpdump 输出.

                  Im trying to handle tcpdump output in python.

                  我需要的是运行 tcpdump(它捕获数据包并为我提供信息)并读取输出并处理它.

                  What I need is to run tcpdump (which captures the packets and gives me information) and read the output and process it.

                  问题是 tcpdump 一直在运行,我需要在它输出后立即读取数据包信息并继续执行.

                  The problem is that tcpdump keeps running forever and I need to read the packet info as soon as it outputs and continue doing it.

                  我尝试查看 python 的子进程并尝试使用 popen 调用 tcpdump 并通过管道传输标准输出,但它似乎不起作用.

                  I tried looking into subprocess of python and tried calling tcpdump using popen and piping the stdout but it doesnt seem to work.

                  有关如何进行此操作的任何说明.

                  Any directions on how to proceed with this.

                  import subprocess
                  
                  def redirect():
                      tcpdump = subprocess.Popen("sudo tcpdump...", stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
                      while True:
                          s = tcpdump.stdout.readline()
                          # do domething with s
                  
                  redirect()
                  

                  推荐答案

                  您可以使用-l"使 tcpdump 行缓冲.然后你可以使用 subprocess 来捕获输出.

                  You can make tcpdump line-buffered with "-l". Then you can use subprocess to capture the output as it comes out.

                  import subprocess as sub
                  
                  p = sub.Popen(('sudo', 'tcpdump', '-l'), stdout=sub.PIPE)
                  for row in iter(p.stdout.readline, b''):
                      print row.rstrip()   # process here
                  

                  这篇关于在 python 中处理 tcpdump 输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:python中存根文件(.pyi)的用途是什么? 下一篇:在 Windows 中使用子进程 Popen.send_signal(CTRL_C_EVENT) 时如何达到预期的效果?

                  相关文章

                  <i id='kG2xF'><tr id='kG2xF'><dt id='kG2xF'><q id='kG2xF'><span id='kG2xF'><b id='kG2xF'><form id='kG2xF'><ins id='kG2xF'></ins><ul id='kG2xF'></ul><sub id='kG2xF'></sub></form><legend id='kG2xF'></legend><bdo id='kG2xF'><pre id='kG2xF'><center id='kG2xF'></center></pre></bdo></b><th id='kG2xF'></th></span></q></dt></tr></i><div id='kG2xF'><tfoot id='kG2xF'></tfoot><dl id='kG2xF'><fieldset id='kG2xF'></fieldset></dl></div>

                  <small id='kG2xF'></small><noframes id='kG2xF'>

                      • <bdo id='kG2xF'></bdo><ul id='kG2xF'></ul>
                    1. <tfoot id='kG2xF'></tfoot>

                      <legend id='kG2xF'><style id='kG2xF'><dir id='kG2xF'><q id='kG2xF'></q></dir></style></legend>