Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

pcap2mpeg

by walto (Pilgrim)
on Jan 09, 2008 at 14:50 UTC ( [id://661366]=sourcecode: print w/replies, xml ) Need Help??
Category: Networking Code
Author/Contact Info
Description: pcap2mpeg is a script to extract data from a network capture of an IPTV session and saves it to a file which can be viewed as mpeg. IPTV uses the UDP protocol and is (in this case) sent via multicast addresses. The capture has to be in pcap format (tcpdump or wireshark).
#!/usr/bin/perl -w
#
# Converts tcpdump or wireshark capture
# from pcap format into mpeg video file
# It only converts packets from multicast adresses
# Usage: pcap2mpeg.pl -l LOGFILE -o OUTPUTFILE

use strict;
use Net::TcpDumpLog;
use NetPacket::IP;
use NetPacket::UDP qw(:strip);
use Getopt::Long;

my $outfile = '';
my $logfile = '';

GetOptions( 'l|logfile=s' => \$logfile, 'o|outfile=s' => \$outfile, );
die "Usage: pcap2mpeg.pl -l LOGFILE -o OUTFILE"
  unless ( defined $logfile && defined $outfile );

open OUT, ">>$outfile" or die "Can not open $outfile $!\n";

my $log = Net::TcpDumpLog->new();
$log->read("$logfile");
my @Indexes = $log->indexes;

foreach my $index (@Indexes) {
    my ( $length_orig, $length_incl, $drops, $secs, $msecs ) = $log->h
+eader($index);
    my $data = $log->data($index);
    my ( $ether_dest, $ether_src, $ether_type, $ether_data ) = unpack(
+ 'H12H12H4a*', $data );
    my $ip_obj   = NetPacket::IP->decode($ether_data);
    my @bytes_ip = split /\./, ( $ip_obj->{dest_ip} );
    my $udp_obj  = NetPacket::UDP->decode( $ip_obj->{data} );
    if ( $bytes_ip[0] >= 224 and $bytes_ip[0] <= 240 ){    # only extr
+act data from multicast addresses
        my $data_neu = $udp_obj->{data};
        print OUT $data_neu;
    }
}
Replies are listed 'Best First'.
Re: pcap2mpeg
by Anonymous Monk on Mar 16, 2012 at 23:07 UTC

    The script mentioned does not work

      The script mentioned does not work

      Sure it does

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://661366]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-24 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found