linux - Tcpdump 通过文件轮换将 pcap 写入远程服务器
问题描述
我正在尝试在 linux 机器上运行 tcpdump,它需要在远程服务器上写入 pcap,每 10 秒轮换一次文件。
tcpdump -s0 -i eth0 -G 10 -w - | ssh {remote_ip} "cat > capture_%d-%m_%Y__%H_%M.pcap"
该文件在第一个周期(10 秒)在远程服务器上返回,然后我收到以下错误。
tcpdump: listening on ens224, link-type EN10MB (Ethernet), capture size 262144 bytes
tcpdump: Can't write to standard output: Bad file descriptor
我正在使用-G
基于时间的轮换,如果我删除-G
,那么我可以连续写入远程服务器。
我的远程服务器配置为此主机的无密码登录。
解决方案
您可以通过管道将 tcpdump 传输到另一个 tcpdump,因此在您的情况下:
tcpdump -i eth0 -w - not port 22 | \
ssh my.remote.host tcpdump -r - -w /tmp/capture_%d-%m_%Y__%H_%M_%S.pcap -G 2 -C 100
推荐阅读
- c# - 为什么使用 Environment.Exit() 时需要返回,而不是抛出异常?
- javascript - 在wordpress中使用ajax上传多个文件
- javascript - 有没有办法通过javascript找出Chrome的媒体设置环境?
- scala - 如何在 sbt 项目中添加需要身份验证的存储库
- android - BLE - 蓝牙 GATT 服务无法关闭连接
- android - 即使正在调用 setState,Flutter 开关在点击后也不会改变
- python - 如何消除python数据框中列和行的索引值?
- azure-pipelines - 每个项目的自动递增版本号
- laravel - Passport 无法生成刷新令牌
- shell - 在 Amazon AWS 上使用 Shell 脚本登录 Bluehost FTP