如何用nmap提取某一个文件

更新时间:02-07 教程 由 凉堇年♀ 分享

如何用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'(?

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()

声明:关于《如何用nmap提取某一个文件》以上内容仅供参考,若您的权利被侵害,请联系13825271@qq.com
本文网址:http://www.25820.com/tutorial/14_2191085.html