Ai
1 Star 0 Fork 0

小义的爸爸/pentestpackage

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
NmapParser.py 2.02 KB
一键复制 编辑 原始数据 按行查看 历史
Leon Teale 提交于 2017-01-25 19:13 +08:00 . updated entire repo from private
#!/usr/bin/env python
import csv
import sys
# Name of file
finput = sys.argv[1]
fout_suffix = "_nmap.csv"
cols = ['PORT', 'STATE', 'SERVICE', 'VERSION']
def getIP(line):
if not line: return None
if 'Nmap scan report for' in line:
return line[21:-1]
return ''
def findHead(line):
if not line: return False
for i in cols:
if i not in line:
return False
return True
def parseData(line):
data = []
for i in line.split():
if i.isspace(): continue
if len(data) == 0:
for j in i.strip().split('/'):
data.append(j)
else:
data.append(i.strip())
# Get the version type
i = 4
version = ''
while i < len(data):
version += ' ' + data[i]
data.remove(data[i])
if version:
data.append(version.strip())
return data
def checkLine(line):
for i in line:
if i.isdigit(): continue
if i == '/': return True
return False
# Open the file
with open(finput, 'r') as fin:
while True:
# Get IP address
while True:
ip = getIP(fin.readline())
if ip != '': break
if ip == None:
break
# Get first column from port scan
while not findHead(fin.readline()):
pass
# Get all data
data = []
while True:
line = fin.readline()
# All lines stating with '|' will be ignored
if line[0] == '|': continue
# Check if line is invalid
if not checkLine(line): break
# Record the line
data.append(parseData(line))
# Output into file
with open(ip + fout_suffix, 'wb') as csvfile:
# Get file to be written
rows = csv.writer(csvfile)
cols.insert(1, 'PROTOCOL')
rows.writerow(cols)
cols.remove('PROTOCOL')
# Print all the rows
rows.writerows(data)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Shell
1
https://gitee.com/csharphpython/pentestpackage.git
git@gitee.com:csharphpython/pentestpackage.git
csharphpython
pentestpackage
pentestpackage
master

搜索帮助