-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnmap2csv
executable file
·45 lines (40 loc) · 1.55 KB
/
nmap2csv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/perl -w
use strict;
my @fieldNames = (
"Host:",
"Ports:",
"OS:",
"Seq Index:",
"IPID Seq:"
);
my $split = join "|", @fieldNames;
$split = "($split)";
while( <> ){
foreach my $fieldName ( @fieldNames ){
if( $_ =~ m/$fieldName/ ){
my ( $pre, $post ) = split $fieldName, $_ ;
my ( $fieldVal, @junk ) = split /$split/, $post;
if( $fieldName eq "Host:" ){
$fieldVal =~ m/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\s+\((.*)\)/;
my $dottedDecIp = $1;
my $ipName = $2;
print "\"$dottedDecIp\",\"$ipName\",";
}
elsif( $fieldName eq "OS:" ){
my $os = $fieldVal;
$os =~ s/^\s+//;
$os =~ s/\s+$//;
print "\"$os\",";
}
elsif( $fieldName eq "Ports:" ){
my( @ports ) = $fieldVal =~ m/\s+([0-9]+)\/open/g;
print "\"";
foreach my $port ( @ports ){
print "$port,";
}
print "\"";
}
}
}
print "\n";
}