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

miFor miforcn at gmail.com
Wed Jun 18 00:40:12 PDT 2008


#!/usr/bin/perl
open FD,"tcpdump -i eth0|";
while(<FD>){
    print $_;
}

2008/6/18 gary.jsz <gary.jsz at gmail.com>:

>  系统: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
>
> _______________________________________________
> China-pm mailing list
> China-pm at pm.org
> http://mail.pm.org/mailman/listinfo/china-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/china-pm/attachments/20080618/f0775174/attachment-0001.html 


More information about the China-pm mailing list