| 1 | package App::pscan::Command::Discover; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use base qw( App::pscan::Scanner App::pscan::Command); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | print "POE::Component::Client::Ping requires root privilege\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$> and $^O ne "VMS"
MC/DC0%0/2
$> and $^O ne "VMS"
$>
$^O ne "VMS"
Truth table33%1/3
A and B
A= $>B= $^O ne "VMS"
| |||||||||||||||||||||||||||||
| 8 | if $> and ( $^O ne 'VMS' ); | ||||||||||||||||||||||||||||
| 9 | } | ||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use POE; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use POE::Component::Client::Ping; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use App::pscan::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | App::pscan::Command::Discover - test the range of ips with Ping | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | tcp scan of a given range of the format of Net::IP and a port range. | ||||||||||||||||||||||||||||
| 21 | e.g.: 192.168.1.0/24 | ||||||||||||||||||||||||||||
| 22 | 192.168.1.1 | ||||||||||||||||||||||||||||
| 23 | www.google.it | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub options { | ||||||||||||||||||||||||||
|
Subroutine
options: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 0 | ( "verbose" => "verbose" ); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub scan() { | ||||||||||||||||||||||||||
|
Subroutine
scan: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 34 | 0 | info 'Ping for ' . $self->{'IP'}->ip(); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | POE::Component::Client::Ping->spawn( | |||||||||||||||||||||||||||
| 37 | Alias => 'pinger', # The component's name will be "pinger". | ||||||||||||||||||||||||||||
| 38 | Timeout => 15, # The default ping timeout. | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # Create a session that will use the pinger. Its parameters match | ||||||||||||||||||||||||||||
| 42 | # event names with the functions that will handle them. | ||||||||||||||||||||||||||||
| 43 | POE::Session->create( | ||||||||||||||||||||||||||||
| 44 | inline_states => { | ||||||||||||||||||||||||||||
| 45 | _start => | ||||||||||||||||||||||||||||
| 46 | \&client_start, # Call client_start() to handle "_start". | ||||||||||||||||||||||||||||
| 47 | pong => | ||||||||||||||||||||||||||||
| 48 | \&client_got_pong, # Call client_got_pong() to handle "pong". | ||||||||||||||||||||||||||||
| 49 | }, | ||||||||||||||||||||||||||||
| 50 | 0 | args => [ $self->{'IP'} ] | |||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # Start POE's main loop. It will only return when everything is done. | ||||||||||||||||||||||||||||
| 54 | 0 | $poe_kernel->run(); | |||||||||||||||||||||||||||
| 55 | 0 | exit; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub client_start { | ||||||||||||||||||||||||||
|
Subroutine
client_start: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 0 | my ( $kernel, $session, $ip ) = @_[ KERNEL, SESSION, ARG0 ]; | |||||||||||||||||||||||||||
| 61 | 0 | info "Starting to ping hosts"; | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | # info "Pinging ".$ip->ip()." at ", scalar(localtime); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # "Pinger, do a ping and return the results as a pong event. The | ||||||||||||||||||||||||||||
| 66 | # address to ping is $ping." | ||||||||||||||||||||||||||||
| 67 | 0 | $kernel->post( pinger => ping => pong => $ip->ip ); | |||||||||||||||||||||||||||
| 68 | } while ( ++$ip ); | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # Handle a "pong" event (returned by the Ping component because we | ||||||||||||||||||||||||||||
| 72 | # asked it to). Just display some information about the ping. | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub client_got_pong { | ||||||||||||||||||||||||||
|
Subroutine
client_got_pong: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | 0 | my ( $kernel, $session ) = @_[ KERNEL, SESSION ]; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # The original request is returned as the first parameter. It | ||||||||||||||||||||||||||||
| 77 | # contains the address we wanted to ping, the total time to wait for | ||||||||||||||||||||||||||||
| 78 | # a response, and the time the request was made. | ||||||||||||||||||||||||||||
| 79 | 0 | my $request_packet = $_[ARG0]; | |||||||||||||||||||||||||||
| 80 | my ( $request_address, $request_timeout, $request_time ) | ||||||||||||||||||||||||||||
| 81 | 0 | = @{$request_packet}; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # The response information is returned as the second parameter. It | ||||||||||||||||||||||||||||
| 84 | # contains the response address (which may be different from the | ||||||||||||||||||||||||||||
| 85 | # request address), the ping's round-trip time, and the time the | ||||||||||||||||||||||||||||
| 86 | # reply was received. | ||||||||||||||||||||||||||||
| 87 | 0 | my $response_packet = $_[ARG1]; | |||||||||||||||||||||||||||
| 88 | my ( $response_address, $roundtrip_time, $reply_time ) | ||||||||||||||||||||||||||||
| 89 | 0 | = @{$response_packet}; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # It is impossible to know ahead of time how many ICMP ping | ||||||||||||||||||||||||||||
| 92 | # responses will arrive for a particular address, so the component | ||||||||||||||||||||||||||||
| 93 | # always waits PING_TIMEOUT seconds. An undefined response address | ||||||||||||||||||||||||||||
| 94 | # signals that this waiting period has ended. | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ( defined $response_address ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | info sprintf( "Pinged %-15.15s - Response from %-15.15s in %6.3fs", | |||||||||||||||||||||||||||
| 97 | $request_address, $response_address, $roundtrip_time ); | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | else { | ||||||||||||||||||||||||||||
| 100 | # notice "Time's up for responses from $request_address."; | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 1 | 1; | |||||||||||||||||||||||||||