[tpm] how to detect ICMP 'port unreachable'?

Kartik Thakore thakore.kartik at gmail.com
Tue Mar 16 06:53:12 PDT 2010


Hi Fulko,

Something like this perhaps. Haven't tested it.

Cheers!

__PERL__

use strict;
use Net::Pcap;
use NetPacket::ICMP qw/ICMP_UNREACH/;

my $err = '';
my $dev = Net::Pcap::pcap_lookupdev(\$err);

die $err if $err;

my $pcap = Net::Pcap::pcap_open_live($dev, 1024,1,0,\$err);

die $err if $err;

sub process_pkt {
 my( $user_data, $header, $packet) = @_;
 
 my $icmp_obj = NetPacket::ICMP->decode($packet);

 warn 'ICMP UNREACH CODE CAUGHT' if ($icmp_obj->type == ICMP_UNREACH);

}

Net::Pcap::pcap_loop($pcap, 10, \&process_pkt, "Demo");

Net::Pcap::pcap_close($pcap);

__END_PERL__


More information about the toronto-pm mailing list