{"id":2676,"date":"2016-05-14T16:12:16","date_gmt":"2016-05-14T08:12:16","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2676"},"modified":"2016-05-14T16:12:16","modified_gmt":"2016-05-14T08:12:16","slug":"%e7%94%a8python%e8%a7%a3%e6%9e%90masscannmap%e7%9a%84%e6%89%ab%e6%8f%8f%e7%bb%93%e6%9e%9c","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2676.html","title":{"rendered":"\u7528Python\u89e3\u6790Masscan\/Nmap\u7684\u626b\u63cf\u7ed3\u679c"},"content":{"rendered":"<p>=Start=<\/p>\n<h6>\u7f18\u7531\uff1a<\/h6>\n<p>\u505a\u5b89\u5168\u7684\u4e00\u822c\u90fd\u4f1a\u7528\u5230Nmap\u8fdb\u884c\u7aef\u53e3\u626b\u63cf\uff0c\u5728\u5c0f\u8303\u56f4\u5185\u8fdb\u884c\u626b\u63cf\u65f6Nmap\u7edd\u5bf9\u662f\u9996\u9009\u2014\u2014\u4e30\u5bcc\u7684\u626b\u63cf\u9009\u9879\/\u6a21\u5757\u3001\u8f83\u9ad8\u7684\u51c6\u786e\u5ea6\uff1b\u5728\u5927\u8303\u56f4\u7684\u626b\u63cf\u4e2d\uff0c\u4f60\u5e94\u8be5\u9009\u62e9Masscan\uff0c\u56e0\u4e3a\u5b83\u901f\u5ea6\u5947\u5feb\uff0c\u800c\u4e14\u51c6\u786e\u7387\u8fd8\u53ef\u4ee5\u63a5\u53d7\u3002\u5b83\u4eec\u90fd\u652f\u6301\u81ea\u5b9a\u4e49\u7ed3\u679c\u7684\u8f93\u51fa\u683c\u5f0f\uff0c\u5176\u4e2d\u6bd4\u8f83\u901a\u7528\u7684\u5c31\u662fXML\u683c\u5f0f\uff08Masscan\u4e3a\u4e86\u5c3d\u91cf\u548cNmap\u505a\u5230\u517c\u5bb9\uff0c\u9664\u4e86\u626b\u63cf\u9009\u9879\u6bd4\u8f83\u50cf\u4e4b\u5916\uff0c\u8f93\u51fa\u7ed3\u679c\u7684XML\u683c\u5f0f\u4e5f\u57fa\u672c\u517c\u5bb9\uff09\u3002\u626b\u63cf\u5b8c\u4e86\u4e4b\u540e\u9700\u8981\u5bf9\u7ed3\u679c\u8fdb\u884c\u89e3\u6790\uff0c\u8fd9\u5c31\u662f\u672c\u6587\u7684\u5177\u4f53\u573a\u666f\u9700\u6c42\u3002<\/p>\n<h5>\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n<h6>1.\u89e3\u6790Masscan\u7684XML\u683c\u5f0f\u626b\u63cf\u7ed3\u679c<\/h6>\n<pre class=\"lang:default decode:true \">#!\/usr\/bin\/env python\n# coding=utf-8\n\nimport sys, time\nimport xmltodict\n\ndef main():\n    with open('.\/masscan_result.xml') as fp:\n        xml_obj = xmltodict.parse(fp.read())\n        nmaprun = xml_obj['nmaprun']\n        host = nmaprun['host']\n        for entry in host[:10]:  #\u8c03\u8bd5\u9636\u6bb5\u53ea\u6253\u5370\u524d10\u6761\u8bb0\u5f55\n            port = entry['ports']['port']\n            if int(port['@portid']) == 80:\n                name = entry['address']['@addr']\n                print 'http:\/\/' + name + '\/'\n            elif int(port['@portid']) == 443:\n                name = entry['address']['@addr']\n                print 'https:\/\/' + name + '\/'\n            elif int(port['@portid']) == 21:\n                name = entry['address']['@addr']\n                print 'ftp:\/\/' + name + '\/'\n            else:\n                name = entry['address']['@addr']\n                print 'http:\/\/' + name + ':' + str(port['@portid']) + '\/'\n\nif __name__ == '__main__':\n    time_start = time.time()\n    try:\n        main()\n    except KeyboardInterrupt:\n        print 'Killed by user'\n        sys.exit(0)\n    print \"Spend {0} seconds.\\n\".format(time.time() - time_start)<\/pre>\n<h6>2.\u89e3\u6790Nmap\u7684XML\u683c\u5f0f\u626b\u63cf\u7ed3\u679c<\/h6>\n<pre class=\"lang:default decode:true \">#!\/usr\/bin\/env python\n# coding=utf-8\n\nimport sys, time\nimport xmltodict\n\ndef main():\n    fp_content = ''\n    try:\n        with open(sys.argv[1]) as fp:\n            fp_content = fp.read().replace('\\n', '')\n    except IOError:\n        print 'File IO Error'\n        sys.exit(-1)\n\n    nmap_xml = xmltodict.parse(fp_content)\n    nmaprun = nmap_xml['nmaprun']\n    scanhost = nmaprun['host']\n    for i in scanhost:\n        address = i['address']['@addr']\n        port1 = dict(i)\n        try:\n            if int(port1['ports']['port']['@portid']) &gt; 0:\n                port2 = port1['ports']['port']['@portid']\n                if port2 == '80':\n                    print 'http:\/\/'+address+'\/'\n                elif port2 == '443':\n                    print 'https:\/\/'+address+'\/'\n                else:\n                    print 'http:\/\/'+address+':'+port2+'\/'\n        except:\n            port2 = i['ports']['port']\n            for z in port2:\n                x = z['@portid']\n                if x == '80':\n                    print 'http:\/\/'+address+'\/'\n                elif x == '443':\n                    print 'https:\/\/'+address+'\/'\n                else:\n                    print 'http:\/\/'+address+':'+x+'\/'\n\nif __name__ == '__main__':\n    time_start = time.time()\n    try:\n        main()\n    except KeyboardInterrupt:\n        print 'Killed by user'\n        sys.exit(0)\n    print \"Spend {0} seconds.\\n\".format(time.time() - time_start)<\/pre>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"https:\/\/github.com\/maK-\/scantastic-tool\">https:\/\/github.com\/maK-\/scantastic-tool<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/martinblech\/xmltodict\">https:\/\/github.com\/martinblech\/xmltodict<\/a><\/li>\n<\/ul>\n<p>=EOF=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u505a\u5b89\u5168\u7684\u4e00\u822c\u90fd\u4f1a\u7528\u5230Nmap\u8fdb\u884c\u7aef\u53e3\u626b\u63cf\uff0c\u5728\u5c0f\u8303\u56f4\u5185\u8fdb\u884c\u626b\u63cf\u65f6Nmap\u7edd\u5bf9\u662f\u9996\u9009\u2014\u2014\u4e30 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,7,25,12],"tags":[604,38,8,600],"class_list":["post-2676","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-programing","category-security","category-tools","tag-masscan","tag-nmap","tag-python","tag-xmltodict"],"views":12531,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2676"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2676\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}