I'm still fairly new to perl, but there is this problem that I can't seem to find a solution for, in the following piece of code, I'm using the net::pcaputils module to capture tcp packets, the code works fine. but the problem is that; I would like to send a tcp ping and capture the response in the same script. If anybody could enlighten me of how to do this, I would greatly appreciate it. Thanks in advance.
#!/usr/bin/perl
use Net::PcapUtils;
use NetPacket::IP;
use NetPacket::TCP;
use NetPacket::Ethernet;
Net::PcapUtils::loop(\&packets, FILTER=>"tcp");
sub packets{
my($user_data, $hdr, $pkt) = @_;
my $eth_data = NetPacket::Ethernet::strip($pkt);
my $np_data = NetPacket::Ethernet->decode($pkt);
my $ip = NetPacket::IP->decode($eth_data);
my $tcp = NetPacket::TCP->decode($ip->{'data'});
$i++; print "($i) Packet Captured:\n";
print "ip/port:: $ip->{'src_ip'}:$tcp->{'src_port'} --> $ip
+->{'dest_ip'}:$tcp->{'dest_port'}\n";
print "mac:: $np_data->{'src_mac'} --> $np_data->{'dest
+_mac'}\n\n";
}
Retitled by davido.
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.