PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : [Perl] Simple CGI Portscanner



Suicide
16.08.2007, 15:50
#!/usr/bin/perl
use warnings;
use CGI ":standard";
use IO::Socket::INET;
use strict;

print header(),start_html("portscanner");

my $port = param('start');
my $ip = param('ip');
my $end = param('end');

print start_form(-method=>'POST',action=>"$ENV{'SCRIPT_NAME'}"),"IP: ",textfield(-name=>'ip'),
"
Starting Port: ",textfield(-name=>'start',size=>'10'),
"
Ending Port: ",textfield(-name=>'end',size=>'11'),"
",
submit(-value=>'Scan'),end_form;

if($port and $ip and $end and $ip ne '127.0.0.1' and $ip !~ m/^192\./){

open(my $log,">>/portscanner_log.txt");
print $log "$ENV{'REMOTE_ADDR'} $ip $port $end\n";
close($log);

while($port<=$end){
my $socket = IO::Socket::INET -> new(PeerAddr=>$ip,PeerPort=>$port,Proto=>"tcp",Tim eout => 0.5);
if($socket != 0){
print "Port $port is opened.
";
}
$port++;
}
}

print end_html();