我们如何抑制 tshark 默认输出。请参阅下面给出的示例输出以获取更多详细信息:
system@client:~$ sudo tshark -q -i eth0 -f "tcp" -a duration:3 -w /tmp/test.pcap
[sudo] password for system:
tshark: Lua: Error during loading:
[string "/usr/share/wireshark/init.lua"]:45: dofile has been disabled
Running as user "root" and group "root". This could be dangerous.
Capturing on eth0
2 packets captured
system@client:~$
==================================================== ==================
试验台:
客户端 <---------------> 服务器
代码示例:
def execTShark(self,cmd):
try:
self.SSHCONN.sendline('')
self.SSHCONN.expect('[#\$>]')
self.SSHCONN.maxread=20000
self.output = ""
self.SSHCONN.sendline( cmd )
while 1:
i = self.SSHCONN.expect (['password', '[#\$>]'])
self.output = self.output + self.SSHCONN.before
if i==0:
self.SSHCONN.sendline(self.password)
elif i==1:
self.SSHCONN.sendline('')
self.SSHCONN.expect (['[#\$>]', 'Capturing'])
self.output = self.output + self.SSHCONN.before
self.SSHCONN.sendline('')
break
self.SSHCONN.expect('[#\$>]')
self.output = self.output + self.SSHCONN.before
print self.output
except Exception as ex:
print("An exception occurred, " + str(ex))
return False
return True
问题:
1.当我调用上述函数时,使用 cmd="sudo tshark -q -i eth0 -f "tcp" -a duration:3 -w /tmp/test.pcap &" execTShark,有时它会失败,同时等待对于此消息“在 eth0 上捕获”。