forked from dgleebits/PythonSystemAdminTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNMAPparser.py
More file actions
47 lines (40 loc) · 1.18 KB
/
Copy pathNMAPparser.py
File metadata and controls
47 lines (40 loc) · 1.18 KB
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
46
47
#/usr/bin/python
'''
This program rips thru text dumps of NMAP text output and puts it into a pickled datafile for PythonPandas analysis
'''
import re
import cPickle as pickle
import datetime
data = ! cat *
newDict = {}
newList = []
splitLine = ['0.0.0.0','0.0.0.0']
pattern = re.compile('[0-9]{1,5}/tcp')
nowTime = datetime.datetime.now().strftime('%Y-%m-%d')
for line in data:
if 'Nmap scan report for ' in line:
cutLine = line[21:]
splitLine = cutLine.split(' ')
if len(splitLine) == 1:
splitLine.insert(1, splitLine[0])
if len(splitLine) == 2:
asdf = splitLine[1].lstrip('(')
asdf = asdf.rstrip(')')
splitLine.insert(1, asdf)
splitLine.pop()
match = pattern.search(line)
if match: # looking for listings of open ports
newList.append(match.group())
if len(line) == 0: # this is the end scan object and creates a DICT with all the objects
newDict [splitLine[0]]=[splitLine[1],newList]
newList = []
# saving pickled file to disk
pickle.dump( newDict, open( "saveNewDict."+nowTime, "wb", True ) )
#printing output
for key, value in newDict.items():
a,b = value
if len(b) > 0:
print
print key, a,
for item in b:
print item,