问题描述
背景
我正在使用pexpect库登录两台远程计算机。一个称为源,另一个称为目标。目标计算机用于运行程序,该程序处理在目标计算机的特定接口上接收到的UDP数据。源计算机用于通过特定接口将pcap文件(包含UDP数据)发送到目标计算机。我编写了一个python脚本,该脚本基本上可以自动执行此过程。该脚本可以正常运行,即源计算机发送数据,目标计算机上的程序接收数据并正确处理。我还添加了一个信号处理程序函数,该函数用于在用户提供SIGINT(Ctrl + C)信号时逐一停止所有进程(由python脚本启动)。这就是问题所在。
问题
要从源计算机发送pcap文件,请使用命令sudo tcpreplay-edit -i interface-name --pps=100 pcap-file.pcap
。 tcpreplay-edit命令需要超级用户权限。目标计算机上的程序无需使用 sudo 即可运行,因为它不需要超级用户特权。当提供SIGINT信号并且python脚本移至信号处理函数时。在此功能中,我首先通过向目标计算机发送命令pkill -9 program-name
来杀死目标计算机上的程序。这将停止目标计算机上的程序。之后,我通过发送命令sudo pkill -9 tcpreplay-edit
来杀死 tcpreplay-edit 。执行此命令后,我使用命令ps -ef | grep tcpreplay-edit| grep -v "grep" | grep -v "sudo" | wc -l
检查源计算机上是否还有任何
def signal_handler(sig,frame):
source.sendline('ps -ef | grep tcpreplay-edit| grep -v "grep" | grep -v "sudo" | wc -l')
no_of_instances = source.expect(["0","1",pexpect.EOF])
print "Number of Tcpreplay instances running: " + str(no_of_instances)
while no_of_instances != 0:
source.sendline('sudo pkill -9 tcpreplay-edit')
command_output = source.expect(["[sudo]",pexpect.EOF])
if command_output == 0: # send password
time.sleep(2)
source.sendline(source_password)
time.sleep(2)
time.sleep(1)
source.sendline('ps -ef | grep tcpreplay-edit| grep -v "grep" | grep -v "sudo" | wc -l')
time.sleep(2)
no_of_instances = source.expect(["0",pexpect.EOF])
print "Number of Tcpreplay instances running: " + str(no_of_instances)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)