安云网 - AnYun.ORG | 专注于网络信息收集、网络数据分享、网络安全研究、网络各种猎奇八卦。
当前位置: 安云网 > 技术关注 > 编程茶楼 > Python > Python解析Masscan/Nmap的扫描结果

Python解析Masscan/Nmap的扫描结果

时间:2016-09-09来源:未知 作者:安云网点击:
1.解析Masscan的XML格式扫描结果 #!/usr/bin/envpython#coding=utf-8importsys,timeimportxmltodictdefmain():withopen(./masscan_result.xml)asfp:xml_obj=xmltodict.parse(fp.read())nmaprun=xml_obj[nmaprun]host=nmaprun[host]forentryinhost[:10]:#调试阶段只打印前10条记录port=entry[ports

1.解析Masscan的XML格式扫描结果 //ANYUN.ORG


//安云网咨询系统

#!/usr/bin/env python
# coding=utf-8

import sys, time
import xmltodict

def main():
    with open('./masscan_result.xml') as fp:
        xml_obj = xmltodict.parse(fp.read())
        nmaprun = xml_obj['nmaprun']
        host = nmaprun['host']
        for entry in host[:10]:  #调试阶段只打印前10条记录
            port = entry['ports']['port']
            if int(port['@portid']) == 80:
                name = entry['address']['@addr']
                print 'http://' + name + '/'
            elif int(port['@portid']) == 443:
                name = entry['address']['@addr']
                print 'https://' + name + '/'
            elif int(port['@portid']) == 21:
                name = entry['address']['@addr']
                print 'ftp://' + name + '/'
            else:
                name = entry['address']['@addr']
                print 'http://' + name + ':' + str(port['@portid']) + '/'

if __name__ == '__main__':
    time_start = time.time()
    try:
        main()
    except KeyboardInterrupt:
        print 'Killed by user'
        sys.exit(0)
    print "Spend {0} seconds.\n".format(time.time() - time_start) 

//copyright AnYun.ORG

2.解析Nmap的XML格式扫描结果 //copyright AnYun.ORG

#!/usr/bin/env python
# coding=utf-8

import sys, time
import xmltodict

def main():
    fp_content = ''
    try:
        with open(sys.argv[1]) as fp:
            fp_content = fp.read().replace('\n', '')
    except IOError:
        print 'File IO Error'
        sys.exit(-1)

    nmap_xml = xmltodict.parse(fp_content)
    nmaprun = nmap_xml['nmaprun']
    scanhost = nmaprun['host']
    for i in scanhost:
        address = i['address']['@addr']
        port1 = dict(i)
        try:
            if int(port1['ports']['port']['@portid']) > 0:
                port2 = port1['ports']['port']['@portid']
                if port2 == '80':
                    print 'http://'+address+'/'
                elif port2 == '443':
                    print 'https://'+address+'/'
                else:
                    print 'http://'+address+':'+port2+'/'
        except:
            port2 = i['ports']['port']
            for z in port2:
                x = z['@portid']
                if x == '80':
                    print 'http://'+address+'/'
                elif x == '443':
                    print 'https://'+address+'/'
                else:
                    print 'http://'+address+':'+x+'/'

if __name__ == '__main__':
    time_start = time.time()
    try:
        main()
    except KeyboardInterrupt:
        print 'Killed by user'
        sys.exit(0)
    print "Spend {0} seconds.\n".format(time.time() - time_start) //copyright AnYun.ORG 


//安云网咨询系统


//安云网,anyun.org


//copyright AnYun.ORG


//本文来自安云网


//内容来自AnYun.ORG

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
验证码: 点击我更换图片
相关内容
推荐内容