[PerlChina] 请教:如何抓取tcpdump的数据?

gary.jsz gary.jsz at gmail.com
Wed Jun 18 00:26:44 PDT 2008


系统:linux   perl版本:5.8
目的:
想使用perl来实时抓取tcpdump数据,并统计10分钟的流量。

我的代码片段如下:
#!/usr/bin/perl -w

#got system time now
my $time_now;
my $time_temp = `date`;
if ($time_temp =~ /(\d\d):(\d\d):(\d\d)/){
  $time_now = ($1*60*60) + ($2*60) + $3;
}

#got tcpdump data
chomp(my @data = `tcpdump -i eth0 -nnn`);
print $time_now;
foreach my $data(@data){
  print $data;
}

遇到的问题:
运行程序之后,无法正确打印 $data ,只停留在启动tcpdump时两行;




Gary.jsz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/china-pm/attachments/20080618/a1ca9a96/attachment-0001.html 


More information about the China-pm mailing list