如何用nmap提取某一个文件
如何用nmap提取某一个文件?
0x00 目标
nmap批量扫描ip段,之后提取扫描结果中开放端口、端口对应服务、以及服务的版本号到txt文件
0x01 扫描
将需要扫描的ip段放在list.txt,然后使用命令按需要给参数
nmap -p xx,xx -sV -sS -T4 -oN nmap.txt -iL list.txt
0x02筛选结果,需要ip、端口、服务、服务版本
学习python没几天,写这个脚本各种查资料,总算还是完成了,附上菜菜的代码
#coding:utf8
import re
f = open('nmap.txt','r')
string = ""
matchIp = re.compile(r'(?![\.\d])((?:(?:2[0-4]\d|25[0-5]|[01]?\d\d?)\.){ 3} (?:2[0-4]\d|25[0-5]|[01]?\d\d?))(?![\.\d])')
matchPort = re.compile(r'\d+/tcp\s+open')
matchSer = re.compile(r'open\s+\w+.+')
for line in f.readlines():
print line
m = ''.join(matchIp.findall(line))
n = ''.join(matchPort.findall(line))[:-4]
s = ''.join(matchSer.findall(line))[6:]
if(m > ''):
string += "ip:" + m + ' '
if(n > ''):
string += 'port:' + n + ' '
if(s > ''):
string += s + ' '
if(m > '' or n > '' or s > ''):
string += '\n'
r = open('r.txt','w')
r.write(string)
r.close()
f.close()
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 如何用nmap提取某一个文件
本文地址: https://pptw.com/jishu/62832.html
