#!/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;
}
}
In reply to pcap2mpeg
by walto
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.