print "Host: "; chop ($host = ); print "Port to start (1-66535): "; chop ($start_port = ); print "Port to finish(1-66535): "; chop ($last_port = ); if ($start_port > $last_port) { print "Error! Start port cannot be bigger then end port. \n Please re-enter start and end ports. \n\n"; exit 1; } if ($start_port < 1) { print "[?] Start port cannot be less than 1. Try entering a different number."; exit 1; } if ($last_port > 66535) { print "The maximun end port number is 66535 [..you gave $last_port]. \n\n"; exit 1; } $serverip= inet_ntoa((gethostbyname($host))[4]); print "[*] Server's IP: [$serverip]\n"; print "[*] Scan Results: "; open(O, ">>ScanLog.txt"); print O "\nYour target host was $host, at ",scalar(localtime), ":\n\n"; while ($start_port <= $last_port) { $con = new IO::Socket::INET (PeerAddr => $host,PeerPort => $start_port,Timeout => 1, Proto => 'tcp'); if (!($con)) { $start_port++; } else { $khost = $start_port; chomp($khost); $sql = "select * from scanner.vulnerabilities"; $sth = $dbh->prepare($sql); $sth->execute or die "SQL Error: $DBI::errstr\n"; my %ref; while (my $row = $sth ->fetchrow_hashref() ){ $ref{ $row ->{'port'}} = $row ->{'Name'} } foreach $key(keys %ref) {foreach $port (@{$ref{$key}{'port'}}) {if($khost=~/^$port/) {chop($po rt) if ($port =~/\.$/); print "\n[!] Port: [$start_port] Service: $key"; print O "[!] Port: [$start_port] Service: $key\n"; $start_port++}}}}} print O "\n ---------------------E-O-F------------------------\n"; close(O);