App-pscan
view release on metacpan or search on metacpan
lib/App/pscan/Command/Discover.pm view on Meta::CPAN
sub options {
( "verbose" => "verbose" );
}
sub scan() {
my $self = shift;
info 'Ping for ' . $self->{'IP'}->ip();
POE::Component::Client::Ping->spawn(
Alias => 'pinger', # The component's name will be "pinger".
Timeout => 15, # The default ping timeout.
);
# Create a session that will use the pinger. Its parameters match
# event names with the functions that will handle them.
POE::Session->create(
inline_states => {
_start =>
\&client_start, # Call client_start() to handle "_start".
pong =>
\&client_got_pong, # Call client_got_pong() to handle "pong".
lib/App/pscan/Command/Udp.pm view on Meta::CPAN
} while ( ++$self->{'IP'} );
# Run the clients until the last one has shut down.
POE::Kernel->run();
exit;
}
sub client_start {
my ( $kernel, $session, $heap, $ip, $port, $Payload )
= @_[ KERNEL, SESSION, HEAP, ARG0, ARG1, ARG2 ];
my $socket = IO::Socket::INET->new( Proto => 'udp', Timeout => 4 );
die "Couldn't create client socket: $!" unless $socket;
$kernel->select_read( $socket, "get_datagram" );
$kernel->delay( timed_out => 4, $socket );
#info "Sending '$message' to $ip, waiting for responses";
my $server_address = pack_sockaddr_in( $port, inet_aton($ip) );
if ( my $result = send( $socket, $Payload, 0, $server_address ) ) {
if ( $result == length($Payload) ) {
info "Message sent to $ip:$port";
}
( run in 0.233 second using v1.01-cache-2.11-cpan-4d50c553e7e )