khan rohail wrote:
> Hi
> Is it possible to check for open ports through NMAP
> (yes) and put the results into a database, through any
> script or tool. 

How about a Perl script? nmap produces very human-readable output, which 
can then be regexp'd and stuffed into a database. Consider the following 
fragment of code:


---------------------
#!/usr/bin/perl

use DBI;

my $data_source = "dbi:DriverName:[EMAIL PROTECTED]:2727";
my $username = "foo";
my $password = "password";

# Connect to the database;
my $dbh = DBI->connect( $data_source, $username, $password ) || die 
$DBI::errstr;

# Process nmap's output
while( <STDIN> )
{
     my $line = $_;

     if( $line =~ /(\d+)\/(\w+)\s+open\s+(\w+)/ )
     {
        my $port     = $1;
        my $protocol = $2;
        my $service  = $3;

        print "Port $port ($service) open for $protocol\n";

        # Make insertion (assumes a table def of:
        # INT id NOT NULL AUTO_INCREMENT
        # INT port
        # VARCHAR protocol
        # VARCHAR service
        my $rows_deleted = $dbh->do( q{
            INSERT INTO table VALUES( NULL, $port, '$protocol', '$service' )
            }, undef, "DONE" ) || die $dbh->errstr;
        
     } # if (open port found)
} # while (eating STDIN)

# Disconnect cleanly
$dbh->disconnect();
---------------------

I do not claim that the DBI stuff is right, as I did not feel like 
installing the MySQL client stuff just for this exercise. ;)


-- 
Josh Glover <[EMAIL PROTECTED]>

Associate Systems Administrator
INCOGEN, Inc.

Reply via email to