[Rio-pm] Duvidas.

Gabriel Blum blum em pobox.com
Terça Junho 29 11:04:46 PDT 2010


Não sei exatamente como o operador <> procede mas ME PARECE que se for igual
arquivo, ele estará esperando uma linha, ou seja, um \n no stream de input
antes de retornar.

Sugiro vc tentar com read() ou recv()...

Outra sugestão é usar um select para seu programa não ficar travado caso o
outro lado falhe, o que costuma ser comum.

Abraços,
GB

2010/6/29 Oscar Marques <oscarbm em gmail.com>

> Senhores (as).
>
> Boa tarde!
> Estou com uma duvida.
>
> Tenho o seguinte codigo:
>
> ===
>
> #!/usr/bin/perl
>
> my $VERSAO = '0.1';
>
> $SIG{'INT'} = 'IGNORE';
> $SIG{'HUP'} = 'IGNORE';
> $SIG{'TERM'} = 'IGNORE';
> $SIG{'CHLD'} = 'IGNORE';
> $SIG{'PS'} = 'IGNORE';
>
> # Remote reboot.
> my $payload1 = ("\x05" . "\x00" x 7);
>
> # Retrieving Wi-Fi SSID
> # cleartext SSID displayed after "21 27 xx xx" in the received datagram.
> my $payload2 = ("\x03" . "\x00" x 7 . "\x21\x27\x00");
>
> # Retrieving WPA2 PSK
> # cleartext WPA2 PSK displayed after "24 27 xx xx" in the received
> datagram.
> my $payload3 = ("\x03" . "\x00" x 7 . "\x23\x27\x00\x00\x24\x27\x00");
>
> my $hostname = @ARGV[0];
> my $port = @ARGV[1];
> my $type = @ARGV[2];
>
> my $msg = "";
>
> sub banner {
> print ("");
> }
>
> banner();
>
> use strict;
> use IO::Socket;
>
> my $sock = new IO::Socket::INET (
> PeerAddr => $hostname,
> PeerPort => $port,
> Proto => 'tcp',
> );
> die "[x] Error: $!\n" unless $sock;
>
> if ($type eq "1") {
>     print $sock $payload1;
>     print "[+] Rebooting\n";
>     my $buf = '';
>     while (defined($buf = <$sock>)) {
>     print $buf;
> }
>
>   } elsif ($type eq "2") {
>     print $sock $payload2;
>     print "[+] Retrieving Wi-Fi SSID\n"
>   } elsif ($type eq "3") {
>     print $sock $payload3;
>     print "[+] Retrieving WPA2 PSK\n"
>   } else {
>     printf "\n [x] Invalid Option ...\n\n";
>     banner();
>   }
>   close($sock);
>   exit(1);
>
> ===
>
> Gostaria de mostar a resposta do Socket na tela (STDOUT).
>
>     my $buf = '';
>     while (defined($buf = <$sock>)) {
>     print $buf;
>
>
> Como proceder?
> Tentei aqui e não consigo mostrar a mensagem.
> Grato Monges!
>
> _______________________________________________
> Rio-pm mailing list
> Rio-pm em pm.org
> http://mail.pm.org/mailman/listinfo/rio-pm
>
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: <http://mail.pm.org/pipermail/rio-pm/attachments/20100629/aa5ecfde/attachment.html>


Mais detalhes sobre a lista de discussão Rio-pm