{"id":174,"date":"2022-01-01T11:52:47","date_gmt":"2022-01-01T03:52:47","guid":{"rendered":"https:\/\/aaaahui.top\/?p=174"},"modified":"2022-08-13T21:31:10","modified_gmt":"2022-08-13T13:31:10","slug":"fofa-spider","status":"publish","type":"post","link":"https:\/\/ahui.blog\/index.php\/2022\/01\/01\/fofa-spider\/","title":{"rendered":"FOFA\u8d44\u4ea7\u722c\u53d6\u811a\u672c"},"content":{"rendered":"<p><strong>\u811a\u672c\u53ef\u6279\u91cf\u722c\u53d6FOFA\u7684\u641c\u7d22\u7ed3\u679c\uff0c\u57fa\u4e8eFOFA\u7684\u4e00\u4e2a\u4e0d\u662f\u516c\u5171\u7684API\uff0c\u56e0\u4e3a\u8fd9\u4e2aAPI\u5e76\u4e0d\u662f\u4e13\u95e8\u4f9b\u7528\u6237\u4f7f\u7528\u7684\uff0c\u57fa\u672c\u548c\u722c\u7f51\u9875\u5dee\u4e0d\u591a\uff0c\u6bd5\u7adf\u722c\u7f51\u9875\u4e0d\u9700\u8981\u9ad8\u7ea7\u4f1a\u5458\uff0c\u53ea\u8981\u4e0d\u722c\u592a\u591a\uff0c\u95ee\u9898\u4e0d\u5927\u7684\u3002<\/strong><\/p>\n<h4>\u811a\u672c\u73af\u5883\uff1a<\/h4>\n<p>python2<\/p>\n<h4>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/h4>\n<p>\u4fee\u6539\u811a\u672c\u4e2d\u7684\u67e5\u8be2\u6761\u4ef6\u7684base64\u5b57\u7b26\u4e32\u90e8\u5206\uff08\u7b2c12\u884c\uff09\u3001\u9700\u8981\u722c\u53d6\u7684\u94fe\u63a5\u8fd8\u662fIP\u8fd8\u662fHOST\uff0c\u6b63\u5219\u4e2d\u7684\u6539\u4e3aip\u3001link\u3001host\uff08\u7b2c53\u884c\uff09\uff0c\u53e6\u5916\u811a\u672c\u540c\u76ee\u5f55\u4e0b\u8981\u653e\u4e00\u4e2aconfig.txt\uff0c\u91cc\u9762\u586b\u5199\u81ea\u5df1\u7684fofa_token\u3002<\/p>\n<h4>\u811a\u672c\u4ee3\u7801\uff1a<\/h4>\n<pre><code class=\"language-python\">import sys\ndefaultencoding = &#039;utf-8&#039;\nif sys.getdefaultencoding() != defaultencoding:\n    reload(sys)\n    sys.setdefaultencoding(defaultencoding)\n\nimport requests\nfrom lxml import etree\nimport re\n\nqbase64 = &quot;YXBwPSJXVVpISUNNUyI%3D&quot;\nconfig = open(&#039;config.txt&#039;,&#039;r&#039;)\ncookie_config=config.readline().strip()\nheader = {\n        &#039;Authorization&#039;:cookie_config\n    }\n\ndef request(url):\n    try:\n        text = requests.get(url,headers=header).text\n        return text\n    except requests.exceptions.ConnectTimeout as a:\n        print(a)\n    except requests.exceptions.ProxyError as b:\n        print(b)\n    except requests.exceptions.ConnectTimeout as c:\n        print(c)\n    except requests.exceptions.ConnectionError as d:\n        print(d)\n\ndef pn_count(url):\n    text = request(url)\n    total_number = re.findall(&#039;&quot;total&quot;:(\\d*)&#039;,text)\n    total_number=int(total_number[0])\n    if (total_number % 10):\n        pn = total_number\/10 + 1\n    else:\n        pn = total_number\/10\n    return pn\n\ndef spider():\n    current_url = &quot;https:\/\/api.fofa.so\/v1\/search?qbase64=&quot; + qbase64\n    pn = pn_count(current_url)\n    print(&quot;spider website is :&quot;+current_url)\n    print(&quot;The results are {} pages in total&quot;.format(pn))\n    stop_page = raw_input(&quot;please input stop page: \\n&quot;)\n    doc = open(&quot;result.txt&quot;, &quot;w+&quot;)\n    for i in range(1,100000):\n        print(&quot;Now write &quot; + str(i) + &quot; page&quot;)\n        pageurl = requests.get(&#039;https:\/\/api.fofa.so\/v1\/search?pn=&#039; + str(i) + &#039;&amp;qbase64=&#039; + qbase64,headers=header)\n        urllist = re.findall(&#039;&quot;link&quot;:&quot;(.*?)&quot;&#039;, pageurl.text)\n        try:\n            for j in urllist:\n                doc.write(j + &quot;\\n&quot;)\n        except:\n            print(&quot;error!!&quot;)\n        if i == long(stop_page):\n            break\n    doc.close()\n    print(&quot;OK,Spider is End .&quot;)\n\ndef main():\n    spider()\n\nif __name__ == &#039;__main__&#039;:\n    main()<\/code><\/pre>\n<p>\u811a\u672c\u6ca1\u6709\u505a\u7684\u7279\u522b\u5b8c\u5584\uff0c\u53ea\u662f\u4e00\u4e2a\u81ea\u7528\u7684\u5c0f\u5de5\u5177\uff0c\u7528\u5230\u7684\u65f6\u5019\u7a0d\u5fae\u6539\u4e00\u70b9\u5c31\u53ef\u4ee5\u4e86\uff0c\u5c31\u6ca1\u6709\u52a0\u89e3\u6790\u53c2\u6570\u7684\u90e8\u5206\uff0c\u6bd5\u7adf\u722c\u4eba\u5bb6\u7f51\u9875\u722c\u592a\u591a\u4e0d\u592a\u5408\u9002\u3002<\/p>\n<p><strong>PS\uff1a\u5982\u679c\u767d\u5e3d\u6c47\u7684\u5e08\u5085\u4eec\u89c9\u5f97\u4e0d\u592a\u597d\u7684\u8bdd\uff0c\u8054\u7cfb\u6211\uff0c\u6211\u628a\u6587\u7ae0\u548c\u811a\u672c\u5220\u4e86~<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u811a\u672c\u53ef\u6279\u91cf\u722c\u53d6FOFA\u7684\u641c\u7d22\u7ed3\u679c\uff0c\u57fa\u4e8eFOFA\u7684\u4e00\u4e2a\u4e0d\u662f\u516c\u5171\u7684API\uff0c\u56e0\u4e3a\u8fd9\u4e2aAPI\u5e76\u4e0d\u662f\u4e13\u95e8\u4f9b\u7528\u6237\u4f7f\u7528\u7684\uff0c\u57fa &#8230; <a title=\"FOFA\u8d44\u4ea7\u722c\u53d6\u811a\u672c\" class=\"read-more\" href=\"https:\/\/ahui.blog\/index.php\/2022\/01\/01\/fofa-spider\/\" aria-label=\"\u7ee7\u7eed\u9605\u8bfbFOFA\u8d44\u4ea7\u722c\u53d6\u811a\u672c\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[24],"class_list":["post-174","post","type-post","status-publish","format-standard","hentry","category-tools","tag-tools"],"_links":{"self":[{"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/posts\/174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/comments?post=174"}],"version-history":[{"count":1,"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/posts\/174\/revisions"}],"predecessor-version":[{"id":175,"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/posts\/174\/revisions\/175"}],"wp:attachment":[{"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/media?parent=174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/categories?post=174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/tags?post=174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}