in reply to Re^3: IO::Socket Bi-directional comm
in thread IO::Socket Bi-directional comm
while ( <$client> ) { next unless /\S/; # blank line if (/quit|exit/i) { last; } elsif (/microsoft/i) {foreach $command(@commands) { print $client "$command\r"; } } else { last; } } continue { }
Now, what happens is I get ALL the output from the first command I sent to $client, but the foreach loop is no longer able to iterate through all of "@commands" because I think it's hanging in the "while" loop. I have tried various things like putting "next;" after "print;", but I either get none of the command output, or I get what I want, but only for the first command, and then the client never closes it's connection (I send "exit" as the third command). I am trying to figure out if I'm just coming at this the wrong way (I have put various print statements within the top "while" loop, as well as trying to create an array to which all output would be stored, and then print the array:while ( <$client> ) { next unless /\S/; # blank line if (/quit|exit/i) { last; } elsif (/microsoft/i) {foreach $command(@commands) { print $client "$command\r"; while( <$client> ) { print;} } } else { last; } } continue { }
None of it is getting the results I want. #######################while ( <$client> ) { while( my @response = <$client>) { next unless /\S/; # blank line if (/quit|exit/i) { last; } elsif (/microsoft/i) {foreach $command(@commands) { print $client "$command\r"; } print @client; } else { last; } } continue { } }
What I wanted to do was print commands to a netcat listener that was setup with "-e cmd.exe" (a la "reverse telnet") and capture all the output to a log file. Print commands to the socket, then do a "while( <$client>)". That seems to get the job done.... snip ... open(LOGFILE,>>"mylog.log") or die "Can't open mylog.log\n"; print $client "$cmds\r"; while( <$client> ) { print LOGFILE; } close $client; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: IO::Socket Bi-directional comm
by zentara (Cardinal) on Jan 30, 2006 at 18:31 UTC |