On Sep 26, Gedi said:

>fully understand the error I am getting and am hoping somebody can point
>me in the right direction.

You should have shown us the error, so that we don't need to run the code.
But as it stands, the code doesn't need to be run.

>#use strict;

Why'd you do that??

>elsif ($selection == 2) {
>     print "\nEnter target: ";
>     chomp(my $target = <STDIN>);
>     print "Enter start port: ";
>     chomp(my $port = <STDIN>);
>     print "Enter end port: ";
>     chomp(my $end_port = <STDIN>);
>     &scan;
>}

The three variables $target, $port, and $end_port are all declared as
lexical variables in that block.  They can't be seen OUTSIDE the block.
That means your function scan() can't see them.  If you didn't call the
function, but rather put the code of the function IN the elsif block,
you'd be ok.

You should pass the variables to the function.

    # ...
    scan($port, $end_port, $target);
  }

  sub scan {
    my ($from, $to, $where) = @_;
    print "Scanning $where | from port $from to $to\n\n";
    for my $p ($from .. $to) {
      print "Port $p is open\n" if IO::Socket::INET->new(
        PeerAddr => $where,
        PeerPort => $p,
        Proto => 'tcp',
        Timeout => 1,
      );
    }
    print "Port scan complete\n\n";
  }

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to