maybe u can better appreciate this code that use also multiprocessing for scan the ports on more process atm 2 no more.
Thank you Mr. Saffioti for the port-scanning code. I have been playing with
some simple network programming scripts recently and your code below is much
more elegant than mine. I'll be stealing parts of it very soon! =) -Chris
if u uncomment the "elses" can look also closed port with a different color.
Hope can help u .
Cya.
Go.
#!/usr/bin/perl -w
#Written by *SAFFIOTI GOFFREDO* #script for scannning of open socket on ports. use IO::Socket; use IPC::Open2; use Term::ANSIColor; use POSIX ":sys_wait_h";
my ($port, $sock, @servers);
my $pid = 0; my($server, $begin, $end) = @ARGV;
&usage if (!$server); $begin = 0 if (!$begin); $end = 65000 if (!$end);
print "Scanning from $begin to $end\n";
my $status; $pid = fork;
if ($pid != 0) {
# for ($port=$begin;$port<=(($begin + $end)/2);$port++) {
for ($port=$begin;$port<=(($end)/2);$port++) {
&scan;;
if ( $sock ) {
print color 'bold blue';
print " Connected on port $port\n";
# print "$!";
}# else {
#print color 'bold blue';
#print " $port not connected\n";
#}
}
my $childpid;
# $status = 1;
while ($status = waitpid(-1, WNOHANG)> 0) { wait; } } else {
# for ($port=(($begin + $end)/2);$port<=$end;$port++){
for ($port=($end/2)+1;$port<=$end;$port++){
&scan;
if ( $sock ) {
print color 'bold white';
print " Connected on port $port\n ";
}# else {
# print color 'bold white';
# print " $port not connected\n";
#}
}
}
sub usage{ print "Usage: portscan hostname [start from port to port number]\n"; exit(0); }
sub scan{
$sock = IO::Socket::INET->new(PeerAddr => $server,
PeerPort => $port,
Proto => 'tcp');
}-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
