Has anyone ever messed with writing a port scan detector?
I was trying to use PortSentry on an SGI. Didn't work (go
figure). I've written quite a few network type scripts but
never one that watches more than one port/socket at a time.
So I decided to try writing my own. Here's the compact
version of what I have so far:
#!/usr/perl/bin/perl
use IO::Socket;
use IO::Select;
sub AddSocket {
my $port = $_[0];
$sock = new IO::Socket::INET(Listen => 1, LocalPort => $port);
$sock;
}
$one = "6666";
$two = "6667";
$s = IO::Select->new();
$s->add(AddSocket($one));
$s->add(AddSocket($two));
while (@ready = $s->can_read) {
# Not sure what's next
}
Once I start the program, sw shows both ports being listened
to. As a first step, I just want to figure out which port(s)
got a connection and print that info to the screen.
My problem is, after I connect to either port, how do I
select between the list of listened-to ports? I've tried
the 'select' statement a couple different times but with no
luck.
Anyone have any ideas?
Thanks.
Darrin Moran
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.