>>>>> "CS" == Curt Shaffer <cshaf...@gmail.com> writes:

  CS> OK. So I have tried some things. I guess the largest issue that I
  CS> can't find an answer for elsewhere is how to evaluate variables to
  CS> be >, = or <100 in one evaluation.  Before I get there, obviously
  CS> I need to get the variables.

  CS> @hping_array = ();

you are not using strict and warnings. always ask perl for all the help
it can give you.

  CS> $hcount = 1;
  CS> for (; $hcount < 5;){

that is not perlish.

        for ( 1 .. 5 ) {

no need for a counter since you don't even use it.

  CS>         system ("sudo hping3 $domain -S -p 80 -c 1|awk '{print $5}'");

system doesn't return any output to the program, just to stdout. you
need qx or backticks to do this. and why shell out to awk when perl can
do that for you?

        my $hping = `sudo hping3 $domain -S -p 80 -c 1` ;

then parse out the field value you want. i don't know hping3's format
but you seem to want the 5th white space separated field. this could be
off by one as iirc awk is 1 based on fields but perl is 0 based.

        push( @hpings, (split ' ', $hping)[5] ;


  CS>         chomp;

that is chomping $_ is not even set. enabling warnings would have told
you this.

  CS>         push hping_array, $_;

where is the @ in that array name? that won't even compile. please make
sure your code at least compiles before posting it.

you seem to think system puts its output into $_. where did you get that
idea? 

  CS>         $hcount++;

not needed as i said above

  CS> }
  CS> print "@hping_array\n";

  CS> So the code is trying to run the hping3 command against $domain. I
  CS> am awking for $5 which is the IPID value in the response. I am
  CS> trying to push it into the array @hping_array. This should happen
  CS> 5 times.

well, it doesn't. 


  CS> Then I'm printing @hping_array. I'm only getting one value and it
  CS> is actually the whole response from hping. It seems to not respect
  CS> the awk.

no, that isn't true. the system call is sending hping's output to stdout
(via awk but maybe that code is broken too. my awk is massively
rusty). your print is printing nothing (which warnings would also have
told you).

  CS> I have done this partially with just doing my $hping_result =
  CS> `sudo hping3 $domain -S -p 80 -c 1|awk '{print $5}'; So I know the
  CS> system command by itself is working.

if you know about backticks, why did you switch to system? please read
the docs and learn the difference between the two.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to