D
Default
Hi, i just started programming a month ago.
I know almost nothing... any sort of help with this script
would be excellent.
For some reason the script seems to do the same thing with
or without the alarm thing in there. Does this alarm work on w2k?
Also although i may be able to work this out eventually, any tips on
how to display the current port in a more effective way would be very
helpfull.
Here is the script.
#!
use strict;
use warnings;
use Socket;
$| = 1;
my ($internet_addr, $paddr, $remote_port, $remote_host, $kidpid1,
$kidpid2, $kidpid3, @ports_even1, @ports_odd1, @ports_even2,
@ports_odd2,);
my $counter = 1;
my $p_e_loader1 = 2;
my $p_o_loader1 = 1;
my $p_e_loader2 = 514;
my $p_o_loader2 = 513;
print "\n" . ' ' . '='x78 . "\n";
print "\t\t\t\tPort Scanner\n";
print ' ' . '='x78 . "\n\n";
while ($counter <= 256)
{
push (@ports_even1, $p_e_loader1);
$p_e_loader1++;$p_e_loader1++;
$counter++;
if ($counter >= 250) {print "\n@ports_even1\n";my $pause = <STDIN>;}
}
$counter = 1;
while ($counter <= 256)
{
push (@ports_odd1, $p_o_loader1);
$p_o_loader1++;$p_o_loader1++;
$counter++;
}
$counter = 1;
while ($counter <= 256)
{
push (@ports_even2, $p_e_loader2);
$p_e_loader2++;$p_e_loader2++;
$counter++;
}
$counter = 1;
while ($counter <= 256)
{
push (@ports_odd2, $p_o_loader2);
$p_o_loader2++;$p_o_loader2++;
$counter++;
}
undef $counter;
#resolve targets address
$remote_host = shift || 'localhost';
$internet_addr = inet_aton($remote_host) ||
die "Couldn't resolve $remote_host"."'s address\n($!)\n($^E)*";
#create two processes
die "can't fork\n($!)\n($^E)\n*" unless defined($kidpid1 = fork());
if ($kidpid1) #first parent process
{
foreach $remote_port (@ports_even1)
{
print "\b\b\b\b \b\b\b\b";
print "$remote_port"
socket(SOCK_OUT, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
$paddr = sockaddr_in($remote_port, $internet_addr);
if (connect(SOCK_OUT, $paddr))
{print "\nPort: $remote_port is open.\n";}
eval
{
local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
alarm 1;
close(SOCK_OUT);
alarm 0;
};
}
}
else #first child process
{
#create a third process
die "can't fork\n($!)\n($^E)\n*" unless defined($kidpid2 = fork());
if ($kidpid2) #second parent process
{
foreach $remote_port (@ports_odd1)
{
print "\b\b\b\b \b\b\b\b";
print "$remote_port"
socket(SOCK_OUT, PF_INET, SOCK_STREAM,
getprotobyname('tcp'));
$paddr = sockaddr_in($remote_port, $internet_addr);
if (connect(SOCK_OUT, $paddr))
{print "\nPort: $remote_port is open.\n";}
eval
{
local $SIG{ALRM} = sub { die "alarm\n" };
alarm 1;
close(SOCK_OUT);
alarm 0;
};
}
}
else #second child process
{
#create a fourth process
die "can't fork\n($!)\n($^E)\n*" unless defined($kidpid3=fork());
if ($kidpid3) #third parent process
{
foreach $remote_port (@ports_even2)
{
print "\b\b\b\b \b\b\b\b";
print "$remote_port"
socket(SOCK_OUT, PF_INET, SOCK_STREAM,
getprotobyname('tcp'));
$paddr = sockaddr_in($remote_port, $internet_addr);
if (connect(SOCK_OUT, $paddr))
{print "\nPort: $remote_port is open.\n";}
eval
{
local $SIG{ALRM} = sub { die "alarm\n" };
alarm 1;
close(SOCK_OUT);
alarm 0;
};
}
}
else
{
foreach $remote_port (@ports_odd2)
{
print "\b\b\b\b \b\b\b\b";
print "$remote_port";
socket(SOCK_OUT, PF_INET, SOCK_STREAM,
getprotobyname('tcp'));
$paddr = sockaddr_in($remote_port, $internet_addr);
if (connect(SOCK_OUT, $paddr))
{print "\nPort: $remote_port is open.\n";}
eval
{
local $SIG{ALRM} = sub { die "alarm\n" };
alarm 1;
close(SOCK_OUT);
alarm 0;
};
}
}
}
}
kill("TERM", $kidpid1);
kill("TERM", $kidpid2);
kill("TERM", $kidpid3);
print "\nDone.\n" && exit;
I know almost nothing... any sort of help with this script
would be excellent.
For some reason the script seems to do the same thing with
or without the alarm thing in there. Does this alarm work on w2k?
Also although i may be able to work this out eventually, any tips on
how to display the current port in a more effective way would be very
helpfull.
Here is the script.
#!
use strict;
use warnings;
use Socket;
$| = 1;
my ($internet_addr, $paddr, $remote_port, $remote_host, $kidpid1,
$kidpid2, $kidpid3, @ports_even1, @ports_odd1, @ports_even2,
@ports_odd2,);
my $counter = 1;
my $p_e_loader1 = 2;
my $p_o_loader1 = 1;
my $p_e_loader2 = 514;
my $p_o_loader2 = 513;
print "\n" . ' ' . '='x78 . "\n";
print "\t\t\t\tPort Scanner\n";
print ' ' . '='x78 . "\n\n";
while ($counter <= 256)
{
push (@ports_even1, $p_e_loader1);
$p_e_loader1++;$p_e_loader1++;
$counter++;
if ($counter >= 250) {print "\n@ports_even1\n";my $pause = <STDIN>;}
}
$counter = 1;
while ($counter <= 256)
{
push (@ports_odd1, $p_o_loader1);
$p_o_loader1++;$p_o_loader1++;
$counter++;
}
$counter = 1;
while ($counter <= 256)
{
push (@ports_even2, $p_e_loader2);
$p_e_loader2++;$p_e_loader2++;
$counter++;
}
$counter = 1;
while ($counter <= 256)
{
push (@ports_odd2, $p_o_loader2);
$p_o_loader2++;$p_o_loader2++;
$counter++;
}
undef $counter;
#resolve targets address
$remote_host = shift || 'localhost';
$internet_addr = inet_aton($remote_host) ||
die "Couldn't resolve $remote_host"."'s address\n($!)\n($^E)*";
#create two processes
die "can't fork\n($!)\n($^E)\n*" unless defined($kidpid1 = fork());
if ($kidpid1) #first parent process
{
foreach $remote_port (@ports_even1)
{
print "\b\b\b\b \b\b\b\b";
print "$remote_port"
socket(SOCK_OUT, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
$paddr = sockaddr_in($remote_port, $internet_addr);
if (connect(SOCK_OUT, $paddr))
{print "\nPort: $remote_port is open.\n";}
eval
{
local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
alarm 1;
close(SOCK_OUT);
alarm 0;
};
}
}
else #first child process
{
#create a third process
die "can't fork\n($!)\n($^E)\n*" unless defined($kidpid2 = fork());
if ($kidpid2) #second parent process
{
foreach $remote_port (@ports_odd1)
{
print "\b\b\b\b \b\b\b\b";
print "$remote_port"
socket(SOCK_OUT, PF_INET, SOCK_STREAM,
getprotobyname('tcp'));
$paddr = sockaddr_in($remote_port, $internet_addr);
if (connect(SOCK_OUT, $paddr))
{print "\nPort: $remote_port is open.\n";}
eval
{
local $SIG{ALRM} = sub { die "alarm\n" };
alarm 1;
close(SOCK_OUT);
alarm 0;
};
}
}
else #second child process
{
#create a fourth process
die "can't fork\n($!)\n($^E)\n*" unless defined($kidpid3=fork());
if ($kidpid3) #third parent process
{
foreach $remote_port (@ports_even2)
{
print "\b\b\b\b \b\b\b\b";
print "$remote_port"
socket(SOCK_OUT, PF_INET, SOCK_STREAM,
getprotobyname('tcp'));
$paddr = sockaddr_in($remote_port, $internet_addr);
if (connect(SOCK_OUT, $paddr))
{print "\nPort: $remote_port is open.\n";}
eval
{
local $SIG{ALRM} = sub { die "alarm\n" };
alarm 1;
close(SOCK_OUT);
alarm 0;
};
}
}
else
{
foreach $remote_port (@ports_odd2)
{
print "\b\b\b\b \b\b\b\b";
print "$remote_port";
socket(SOCK_OUT, PF_INET, SOCK_STREAM,
getprotobyname('tcp'));
$paddr = sockaddr_in($remote_port, $internet_addr);
if (connect(SOCK_OUT, $paddr))
{print "\nPort: $remote_port is open.\n";}
eval
{
local $SIG{ALRM} = sub { die "alarm\n" };
alarm 1;
close(SOCK_OUT);
alarm 0;
};
}
}
}
}
kill("TERM", $kidpid1);
kill("TERM", $kidpid2);
kill("TERM", $kidpid3);
print "\nDone.\n" && exit;