And in the spirit of using Perl for reinventing wheels, a TCP packet dumper using Net::PcapUtils ... :-)
use Net::PcapUtils;
use NetPacket::IP;
use NetPacket::TCP;
use NetPacket::Ethernet qw/:types/;
use strict;
Net::PcapUtils::loop(
sub {
my ($arg, $header, $packet) = @_;
my $ethernet = NetPacket::Ethernet->decode($packet);
if ($ethernet->{'type'} == ETH_TYPE_IP) {
my $ip = NetPacket::IP->decode($ethernet->{'data'}, $ether
+net);
my $tcp = NetPacket::TCP->decode($ip->{'data'});
print
$ip->{'src_ip'}, ":", $tcp->{'src_port'}, " -> ",
$ip->{'dest_ip'}, ":", $tcp->{'dest_port'}, "\n\n";
my @data = split //, $tcp->{'data'};
while (@data) {
print "\t";
for (0..7) {
print sprintf("%02x", shift(@data)), " ";
}
print "\n";
}
print "\n";
}
},
'DEV' => 'lo'
);
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|