Hi all,
I have recently started to learn perl. After reading Randal Schwartz’s
Learning perl, I decided to give my first program a whirl.
Upon writing it, I was checking each section of code as I went along to
make sure everything worked.
I got to one section and couldn’t get it to run as a subroutine. I don’t
fully understand the error I am getting and am hoping somebody can point
me in the right direction.
Here is a snippet of my code (edited/reduced to about ¼ of the full
size) which gives the same error as my full program.
#usr/bin/perl -w
#use strict;
use warnings;
use IO::Socket;
print "1. network Listing only\n";
print "2. Port scan only\n";
print "\nPlease enter selection: ";
chomp (my $selection = <STDIN>);
if ($selection == 1) {
#bla bla, don't need this info
}
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;
}
sub scan {
print "Scanning $target | from port $port to $end_port\n\n";
foreach (; $port<=$end_port; $port++) {
if ( IO::Socket::INET->new(
PeerAddr => $target,
PeerPort => $port,
Proto => 'tcp',
Timeout => 1)) {
print "Port $port is open\n";
}
}
print "\nPort scan complete\n";
exit;
}
Can anyone suggest why I am getting an error and how I can fix it?
Thanks
Ged.