我试图编程一个“肮脏”的网站过滤器-例如一个用户想要访问一个色情网站(基于域名)
所以基本上,我得到的是
#!/bin/bash
sudo tshark -i any tcp port 80 or tcp port 443 -V | grep "Host.*keyword"它工作得很好,但是现在我需要在找到一些东西(iptables和DROPing数据包.)之后执行一些操作。我遇到的问题是tcp转储仍然在运行。如果我有一个完整的文件与数据,我想要达到的东西是很容易解决。
在假象中,我想要这样的东西:
if (tshark and grep found something)
iptables - drop packets
sleep 600 # a punishment for an user
iptables accept packets I was dropping
else
still look for a match in the tcp dump that's still running谢谢你的帮助。
发布于 2013-12-01 00:06:50
也许你可以尝试以下几种方法:
tshark OPTIONS 2>&1 | grep --line-buffered PATTERN | while read line; do
# actions for when the pattern is found, the matched input is in $line
break
done2>&1是很重要的,这样当模式匹配和while循环结束时,由于管道中断,tshark没有地方可以写入和终止。
如果希望保持tshark运行并分析未来的输出,只需删除break即可。这样,while循环就不会终止,它会一直读取来自tshark的过滤输出。
https://stackoverflow.com/questions/20306923
复制相似问题