Does alarm work on w2k?

Discussion in 'Perl Misc' started by Default@IO_Error_1011101.xyz, Nov 26, 2003.

  1. 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;
     
    Default@IO_Error_1011101.xyz, Nov 26, 2003
    #1
    1. Advertising

  2. 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.
     
    Default@IO_Error_1011101.xyz, Nov 27, 2003
    #2
    1. Advertising

  3. >
    >
    > 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?
     
    Default@IO_Error_1011101.xyz, Nov 27, 2003
    #3
  4. Default@IO_Error_1011101.xyz

    Anno Siegel Guest

    <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
     
    Anno Siegel, Nov 27, 2003
    #4

  5. > > 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.
     
    Default@IO_Error_1011101.xyz [JDM], Nov 27, 2003
    #5
  6. 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$...
    >
    > Well the currently scanned port is printing in all four threads and they are
    > copying over eachother this looks messy,
     
    Ben Liddicott, Nov 28, 2003
    #6
  7. On Fri, 28 Nov 2003 10:35:51 -0000
    "Ben Liddicott" <> 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
     
    James Willmore, Nov 28, 2003
    #7
  8. Default@IO_Error_1011101.xyz

    Bart Lateur Guest

    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.
     
    Bart Lateur, Nov 29, 2003
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. service

    alarm workaround

    service, Nov 6, 2003, in forum: Perl
    Replies:
    0
    Views:
    590
    service
    Nov 6, 2003
  2. Tim Zych

    Authentication with Zone Alarm?

    Tim Zych, Jan 11, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    322
    Tim Zych
    Jan 11, 2004
  3. honcho
    Replies:
    0
    Views:
    445
    honcho
    Jun 24, 2005
  4. Ole Weigelt

    Greenhorn Alarm

    Ole Weigelt, Sep 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    415
  5. stephen
    Replies:
    0
    Views:
    343
    stephen
    Jun 19, 2006
Loading...

Share This Page