App-pscan

 view release on metacpan or  search on metacpan

lib/App/pscan/Command/Tcp.pm  view on Meta::CPAN

    do {
        for ( $self->{'first'} .. $self->{'last'} ) {
            my $port = $_;
            my $host = $self->{'IP'}->ip() if exists $self->{'IP'};
            POE::Component::Client::TCP->new(
                RemoteAddress => $host,
                RemotePort    => $port,
                Filter        => "POE::Filter::Stream",

              # The client has connected.  Display some status and prepare to
              # gather information.  Start a timer that will send ENTER if the
              # server does not talk to us for a while.
                Connected => sub {
                    info "connected to $host:$port ...";
                    $_[HEAP]->{banner_buffer} = [];
                    $_[KERNEL]->delay( send_enter => 5 );
                },

                # The connection failed.
                ConnectError => sub {

                    #error "could not connect to $host:$port ...";
                },

              # The server has sent us something.  Save the information.  Stop
              # the ENTER timer, and begin (or refresh) an input timer.  The
              # input timer will go off if the server becomes idle.
                ServerInput => sub {
                    my ( $kernel, $heap, $input ) = @_[ KERNEL, HEAP, ARG0 ];
                    notice "got input from $host:$port ...";
                    push @{ $heap->{banner_buffer} }, $input;
                    $kernel->delay( send_enter    => undef );
                    $kernel->delay( input_timeout => 1 );
                },

                # These are handlers for additional events not included in the
                # default Server::TCP module.  In this example, they handle
                # timers that have gone off.
                InlineStates =>
                    { # The server has not sent us anything yet.  Send an ENTER
                     # keystroke (really a network newline, \x0D\x0A), and wait
                     # some more.
                    send_enter => sub {
                        info "sending enter on $host:$port ...";
                        $_[HEAP]->{server}->put($Payload)
                            if $_[HEAP]->{server};    # sends enter
                        $_[KERNEL]->delay( input_timeout => 5 );
                    },



( run in 1.480 second using v1.01-cache-2.11-cpan-49f99fa48dc )