I'm writing a small UDP port scanner that just relys on an ICMP response to detect non-filtered/closed ports.

For some reason my code is returning an ICMP type 69 Code 1 which is not a valid type that I can see. I'd expect a type 3 ( Destination Unreachable ) not an undefined type.

Am I deciphering the ICMP packet I'm receiving wrong? Here is the code I am using:
#!/usr/bin/perl use IO::Socket; # # Scan UDP ports # $|++; my @ports = ( 53, 514, 15555 ); scan_udp_ports( 'localhost', \@ports ); sub scan_udp_ports { my $host = shift; my $ports = shift; my($closed, $open, $filtered); # Setup ICMP listen my $icmp = IO::Socket::INET->new( Proto => 'icmp', Blocking => 0 ) or die("No ICMP listen"); foreach my $port ( @$ports ) { print "Scanning $port\n"; # Setup UDP send connection $client = IO::Socket::INET->new( PeerPort => $port, PeerAddr => $host, Proto => 'udp', Blocking => 0 ) or die("No server $!"); # Send UDP packet $client->send( undef ); sleep( 5 ); my $icmpbuffer = icmp_recv( $icmp ); # Check for response my $flags; if( $client->recv( $dgram, 10, $flags ) ) { print "This udp port $port at host $host responded!\n"; } } } sub icmp_recv { my $icmp = shift; # Listen for ICMP response my $icmpbuffer; if( my $icmpr = $icmp->recv( $icmpbuffer, 1024, 0 ) ) { print "ICMP Type: " . unpack("%8C", $icmpbuffer) . "\n"; print "ICMP Code: " . unpack("%8c", substr($icmpbuffer, 9)) . +"\n"; print "ICMP Checksum: " . unpack("%8c", substr($icmpbuffer, 33 +)) . "\n"; } return $icmpbuffer; }

In reply to Invalid ICMP type 69 by vancetech

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.