How to read a PIPE in unbuffered way?

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

Hi, I'd like to know the Ruby equivalent to the following Perl code:

=2D--------------------
open(PIPE,"ngrep dst port 80 |");
select(PIPE); $| =3D 1; # make unbuffered
select(STDOUT); $| =3D 1; # make unbuffered

while(<PIPE>)
{ =20
chomp($_);
s/
//ig;
s/ // if(/^ /);
#### process and change the captured data before writting to the screen ##=
##
}
close(PIPE);
=2D------------------------

"ngrep" itself is a Linux command that captures TCP/UDP data and prints it =
to=20
the screen. In this case I capture traffic with destination port 80.

I assume I must start with:

f =3D IO.popen("ngrep dst port 80")

but no idea of what to do after that. Any help please? Thanks a lot.



=2D-=20
I=C3=B1aki Baz Castillo
 
R

robhurring

something like this?

IO.popen('ngrep dst port 80').each do |line|
# PROCESS LINE
end
 
A

ara.t.howard

Hi, I'd like to know the Ruby equivalent to the following Perl code:

---------------------
open(PIPE,"ngrep dst port 80 |");
select(PIPE); $| =3D 1; # make unbuffered
select(STDOUT); $| =3D 1; # make unbuffered

while(<PIPE>)
{
chomp($_);
s/
//ig;
s/ // if(/^ /);
#### process and change the captured data before writting to the = =20
screen ####
}
close(PIPE);
-------------------------

"ngrep" itself is a Linux command that captures TCP/UDP data and =20
prints it to
the screen. In this case I capture traffic with destination port 80.

I assume I must start with:

f =3D IO.popen("ngrep dst port 80")

but no idea of what to do after that. Any help please? Thanks a lot.



--=20
I=F1aki Baz Castillo

ammunition

require 'io/nonblock'


http://codeforpeople.com/lib/ruby/nbfifo/nbfifo-0.0.0/README




a @ http://codeforpeople.com/
 
I

Iñaki Baz Castillo

El Jueves, 25 de Septiembre de 2008, (e-mail address removed) escribi=F3:
something like this?

IO.popen('ngrep dst port 80').each do |line|
# PROCESS LINE
end

Great!
Thanks a lot.

=2D-=20
I=F1aki Baz Castillo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top