http://www.perlmonks.org?node_id=143258

rchiav has asked for the wisdom of the Perl Monks concerning the following question:

I'm currently in the process of learning more about network programming. In the Perl Cookbook on page 637, there's a script that logs all attempts to connect to local ports. I thought I'd try to get this to run under Windows, but I'm having some difficulty trying to figure out how to get the same functionality that inetd or xinetd provide. Does anyone have any advice or links to information on how you'd implement something like this? I know this is a pretty vague and general question, but I'm not looking for the answer, just where I might start looking for it.

Thanks,
Rich

Replies are listed 'Best First'.
Re: Getting backsniff from Cookbook to work under Windows
by gellyfish (Monsignor) on Feb 04, 2002 at 17:22 UTC

    In the first edition of Programming Perl there was an example program called receptionist which provided similar functionality to inetd. Of course it is perl 4 but despite the fact that you would probably do things differently now it is still a good example.

    The examples can be found at ftp://ftp.ora.com/published/oreilly/perl/programming_perl/perl.tar.Z

    Added Later:
    Well of course I started to think about this and wondered how I might do this on windows and I came up with this basic example:

    #!/usr/bin/perl -w use strict; use Socket; use IO::Select; use IO::Socket; my $select = IO::Select->new(); while(<DATA>) { chomp; if ( my $server = IO::Socket::INET->new(LocalPort => $_, Listen => 10, ReuseAddr => 1) ) { $select->add($server); } } while(1) { foreach my $ready ($select->can_read(1)) { my $client = $ready->accept(); print inet_ntoa($client->peeraddr()), " ",$client->sockport(),"\n"; } } __DATA__ 2048 2049 2060

    The ports that you want to monitor are the numbers after the __DATA__ . You can probably take the rest from there :)

    /J\