Nmap??????????С????
???????????? ???????[ 2015/4/24 11:28:07 ] ????????Nmap ??? ???????
????????nmap ???ip????????????? IP??PORT??????????????д??????????
import xml.dom.minidom
import sys
import getopt
statstr=""
statstrlist=["open"]
infile=""
outfile=""
infileflag=0
outfileflag=0
statstrflag=0
isstatflag=0
helpflag=0
#chu li can shu
options??args = getopt.getopt(sys.argv[1:]??"hni:o:s:"??["help"??"in="??"out="??"stat"])
for name??value in options:
if name in ("-h"??"--help"):
print """
xxoo.py
-h??--help print this help
-i??--in read the nmap xml outfile
-o??--out out the result (default: xmlname+_done.txt)
-s??--stat splited by dot (example:open.filtered.close default:open)
-n no status info
"""
helpflag=1
if name in ("-i"??"--in"):
infile=value
infileflag=1
if name in ("-o"??"--out"):
outfile=value
outfileflag=1
if name in ("-s"??"--stat"):
statstrlist=value.split(".")
statflag=1
if name=="-n":
isstatflag=1
#chu li mo ren can canshu
if outfileflag==0:
outfile=infile+"_done.txt"
if statstrflag==0:
statstrlist=["open"]
if helpflag==1:
exit()
#chu li dom
file=open(outfile??"w+")
dom=xml.dom.minidom.parse(infile)
root=dom.documentElement
hostlist=root.getElementsByTagName("host")
for hostnode in hostlist:
for hostchild in hostnode.childNodes:
if hostchild.nodeName=="address":
ip=hostchild.getAttribute("addr")
if hostchild.nodeName=="ports":
for hostchildchild in hostchild.childNodes:
if hostchildchild.nodeName=="port":
for stat in statstrlist:
if hostchildchild.childNodes[0].getAttribute("state")==stat:
if isstatflag==0:
print ip+":"+hostchildchild.getAttribute("portid")+"(("+stat+"))"
file.write(ip+":"+hostchildchild.getAttribute("portid")+"(("+stat+"))"+"
")
if isstatflag==1:
print ip+":"+hostchildchild.getAttribute("portid")
file.write(ip+":"+hostchildchild.getAttribute("portid")+"
")
#if hostchildchild.childNodes[0].getAttribute("state")=="open":
#print ip+":"+hostchildchild.getAttribute("portid")+"((open))"
# file.write(ip+":"+hostchildchild.getAttribute("portid")+"((open))"+"
")
#elif hostchildchild.childNodes[0].getAttribute("state")=="filtered":
# print ip+":"+hostchildchild.getAttribute("portid")+"((filtered))"
# file.write(ip+":"+hostchildchild.getAttribute("portid")+"((filtered))"+"
")
file.close()
?????÷???
????????nmap –oX ???????xml???????????tool –i name.xml –s open.filtered
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11