Python 和 NGREP
我希望能够从 python 代码内部启动和停止 NGREP 进程。我确实没有系统级别的 python 经验。
通常我从命令行运行 NGREP,但我希望能够每小时从脚本运行它并捕获跟踪,然后处理结果。
谁能指出我如何实现这一目标的方向。
顺便说一句,我真的只需要能够进行数据包捕获,也许Python有内置的功能,也许是tcpdump?
谢谢。
I want to be able to start and stop an NGREP process from inside my python code. I really dont have experience with python on a system level.
Normally I run NGREP from the command line, but I would like to be able to run it from a script every hour and capture the trace and then process the results.
Can anyone point me in the direction of how to achieve this.
By the way, I really just need to be able to do a packet capture, perhaps Python has builtin capabilities for this, maybe tcpdump?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不是专家,但我会这样做:
您必须以 root 身份或使用 sudo 运行它。
我希望它有帮助!
I am not an expert but I would do this:
You will have to run it as root or with sudo.
I hope it helps!
它不是内置的,但您可以尝试数据包捕获和注入库
its not in-built, but you can try Packet Capture and Injection Library
查找 threading.Timer 和 pexpect。如果您不想安装 pexpect,可以使用 subprocess.Popen 代替。
编辑:响应评论:
编辑2:如果您想手动捕获数据包,请使用 pypcap 。这几乎肯定可以满足您的要求,因为 tcpdump 使用 libpcap 本身。
Look up threading.Timer and pexpect. If you don't want to install pexpect, you can use subprocess.Popen instead.
EDIT: In response to the comment:
EDIT2: If you want to hand-roll the packet capture, use pypcap. This should almost certainly do what you want, since tcpdump uses libpcap itself.