Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Does alarm work on w2k?

Reply
Thread Tools

Does alarm work on w2k?

 
 
Default@IO_Error_1011101.xyz
Guest
Posts: n/a
 
      11-26-2003
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;
 
Reply With Quote
 
 
 
 
Default@IO_Error_1011101.xyz
Guest
Posts: n/a
 
      11-27-2003
Sorry this line should be commented out: LINE 24

> if ($counter >= 250) {print "\n@ports_even1\n";my $pause = <STDIN>;}


Was using that for debugging.
 
Reply With Quote
 
 
 
 
Default@IO_Error_1011101.xyz
Guest
Posts: n/a
 
      11-27-2003
>
>
> Default@IO_Error_1011101.xyz wrote:
> > 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?

>
> No. You can always check the perlport perldoc to see if something is
> not implemented completely or at all for your platform.
>
>

ahhh thanks.. didnt know about perlport.
alarm Not implemented. (Win32)

any ideas about the display issues?
 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      11-27-2003
<Default@IO_Error_1011101.xyz> wrote in comp.lang.perl.misc:
> >
> >
> > Default@IO_Error_1011101.xyz wrote:
> > > 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?

> >
> > No. You can always check the perlport perldoc to see if something is
> > not implemented completely or at all for your platform.
> >
> >

> ahhh thanks.. didnt know about perlport.
> alarm Not implemented. (Win32)
>
> any ideas about the display issues?


You posted 150 lines of code with nothing but a leading comment about alarm.
What display issues?

Anno
 
Reply With Quote
 
Default@IO_Error_1011101.xyz [JDM]
Guest
Posts: n/a
 
      11-27-2003

> > any ideas about the display issues?

>
> You posted 150 lines of code with nothing but a leading comment about alarm.
> What display issues?
>
> Anno
>

Well the currently scanned port is printing in all four threads and they are
copying over eachother this looks messy, ive been trying to get it work better
with curses but when i add curses the program simply ends with no errors at all.
therefore i would like to use simple print statements in a similar fasion to this version
of the script but im not sure how to make the currently scanned port print in one x,y
coord. please note i've started a new thread with the curses version of the script
with the subject Curses %$#@!

Thank You - very much for replying your help is very appreciated.
 
Reply With Quote
 
Ben Liddicott
Guest
Posts: n/a
 
      11-28-2003
Hi Default IO Error,

The basic thing about threads is that things may happen simultaneously, so in order to guarantee that the threads don't write over each other, you need to provide some synchronisation, in general, at any rate.

If you don't need perfection, but just want something better, try either flushing after every write, or turning autoflush on. This will cause output to be sent to the console immediately rather than being buffered, and result in cleaner output, though there are still no guarantees.

For STDOUT:

use English qw(-no-match-vars);
$OUTPUT_AUTOFLUSH=1;


For others, I suggest using IO::Handle and autoflush.

my $stdout = IO::Handle->new_from_fd(STDOUT);
$stdout->autoflush(1);


Cheers,
Ben Liddicott

<Default@IO_Error_1011101.xyz [JDM]> wrote in message news:_Esxb.3378$(E-Mail Removed)...
>
> Well the currently scanned port is printing in all four threads and they are
> copying over eachother this looks messy,

 
Reply With Quote
 
James Willmore
Guest
Posts: n/a
 
      11-28-2003
On Fri, 28 Nov 2003 10:35:51 -0000
"Ben Liddicott" <(E-Mail Removed)> wrote:
> use English qw(-no-match-vars);
> $OUTPUT_AUTOFLUSH=1;


Or more idiomatic Perl:
$| = 1;

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
In a museum in Havana, there are two skulls of Christopher
Columbus, "one when he was a boy and one when he was a man."
-- Mark Twain
 
Reply With Quote
 
Bart Lateur
Guest
Posts: n/a
 
      11-29-2003
Default@IO_Error_1011101.xyz wrote:

>Does this alarm work on w2k?


Since perl 5.8.0, yes. Not on older perls, like 5.6.1. See


<http://groups.google.com/groups?threadm=MPG.18a1bbf086a3da8a989695%40news-central.giganews.com>
<http://perlmonks.org/index.pl?node_id=300279>
<http://perlmonks.org/index.pl?node_id=307024>

--
Bart.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Zone Alarm or Zone Alarm Pro? Jones Computer Information 5 02-20-2004 07:29 PM
eMule worked fine but now eMule Plus doesn't work anymore with Zones Alarm . Ulisse Computer Information 1 11-08-2003 04:42 PM
Audible alarm in Zone Alarm? Patch Computer Support 4 08-18-2003 07:43 PM



Advertisments