python 在远程服务器中运行 tcpdump

问题描述 投票:0回答:1

(我的目的是从 python 运行 tcpdump 而不是退出 python 脚本) 我必须在远程服务器中运行 tcpdump 如果我以通用语法运行 tcp dump 那么我的 python 程序就会卡住,如果我在后台运行它那么跟踪不会开始,只会创建 1kb pcap 文件

ssh_client.connect(host, username=username, password=password)

stdin, stdout, stderr = ssh_client.exec_command("tcpdump -i any -w test.pcap")

# Than pcap starts at remote server but my python program gets stuck
# if i run it with background process than python program doesn't get stuck but there is no packet capture at pcap

stdin, stdout, stderr = ssh_client.exec_command("tcpdump -i any -w test.pcap &")
python tcpdump
1个回答
0
投票

嗨,下面的语法对我有用,我能够启动 tcpdump,甚至 pyhon 程序也不会卡住

stdin, stdout, stderr = ssh_client.exec_command("nohup sudo tcpdump -i eth0 -w test.pcap >/dev/null 2>&1 &")

© www.soinside.com 2019 - 2024. All rights reserved.