vancetech has asked for the wisdom of the Perl Monks concerning the following question:
#!/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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Invalid ICMP type 69
by RMGir (Prior) on Nov 03, 2006 at 19:12 UTC | |
by vancetech (Beadle) on Nov 03, 2006 at 20:51 UTC | |
by NetWallah (Canon) on Nov 04, 2006 at 01:31 UTC | |
|
Re: Invalid ICMP type 69
by NetWallah (Canon) on Nov 03, 2006 at 18:37 UTC | |
by vancetech (Beadle) on Nov 03, 2006 at 19:13 UTC |