Prism has asked for the wisdom of the Perl Monks concerning the following question:

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.

Replies are listed 'Best First'.
Re: How to both send and receive in a Net::PcapUtils loop?
by NetWallah (Canon) on Jan 05, 2005 at 01:50 UTC
    While it is possible to construct a PING packet, I would recommend using a canned method, like Net::Ping to send and receive the ping. This has a TCP ping option (the default).

    If all you are looking for is Ping response time, Net::Ping can provide that info.

    It would probably be best to do the Ping in a different thread, since it blocks, waiting on a response.

        ..."I don't know what the facts are but somebody's certainly going to sit down with him and find out what he knows that they may not know, and make sure he knows what they know that he may not know, and that's a good thing. I think it's a very constructive exchange," --Donald Rumsfeld

      Thanks for the reply, I need more information than just the ping response time though... I'll look into putting the ping in a different thread, thanks.