For instance, suppose I have this co开发者_运维技巧de:
def dump():
tcpdump = subprocess.Popen("tcpdump -nli any",
stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
outputfile = tcpdump.stdout
for line in outputfile:
print line,
How can I serve the output of such to the browser? Since there is no stopping point, I have no idea where to hook with the polling loop. More than that, as print line works (I see lines dumped on the terminal), browser do not get the very same lines, see below:
class TCPDumpHandler(tornado.web.RequestHandler):
def get(self):
self.write("<form method='post' action='/log'><input type='submit'></form>")
@tornado.web.asynchronous
def post(self):
tcpdump = subprocess.Popen("tcpdump -nli any",
stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
outputfile = tcpdump.stdout
for line in outputfile:
print line,
self.write(line)
self.finish()
Redirect tcpdump's output to a file and use this:
https://bitbucket.org/silverspell/tornadolog
Hope it helps :)
精彩评论