1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| import requests from lxml import etree import base64 import time
def Searchresults(results_IP): Searchresults_document = open("url.txt", 'a') Searchresults_document.write((results_IP+'\n')) Searchresults_document.close()
def Multiple(Judge_page,coding,headers,Cookie,speed): print("搜索结果有" + Judge_page + "页") time.sleep(0.5) recording=0 for all in range(1,int(Judge_page)): time.sleep(speed) print("现在提取是第"+str(all)+"页")
html = requests.get('https://fofa.so/result?qbase64=' + coding+"&page="+str(all), headers=headers,cookies=Cookie) html = etree.HTML(html.text) divs = html.xpath(r'//span/a/@href') for results_IP in divs: print("IP地址是" + str(results_IP)) Searchresults(results_IP) recording += 1
if recording >= 50: print("普通用户只能放我50条信息") break
def Determine(html,headers,Cookie,coding,speed): try: html = etree.HTML(html.text) Judge_page = divs = html.xpath(r'//ul[@class="el-pager"]/li[last()]/text()') if Judge_page: Multiple(Judge_page[0],coding,headers,Cookie,speed) else: print("搜索结果就一页!") divs = html.xpath(r'//span[@class="aSpan"]//@href') for results_IP in divs: print("IP地址是" + str(results_IP)) Searchresults(results_IP) except Exception as bc: print("出差了:" + str(bc))
def cfq_insert_request(Cookie,coding,speed): Cookie= {'fofa_token': Cookie} headers = { "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36" } html=requests.get("https://fofa.so/result?qbase64="+str(coding),headers)
Determine(html,headers,Cookie,coding,speed)
def fofa_token(): i = str(input("输入'1'用上一次的Fofa的Cookie值:")) Cookie_fofa_token = 0 if i == '1': fofa_token_document = open("fofa_token.txt", 'r') Cookie_fofa_token = fofa_token_document.readline() fofa_token_document.close() else: Cookie_fofa_token = input("Fofa请输入Cookie值:") fofa_token_document = open("fofa_token.txt", 'w') fofa_token_document.write(Cookie_fofa_token) fofa_token_document.close() return Cookie_fofa_token
if __name__ == '__main__': print(""" __ __ _ _ _ / _| ___ / _| __ _ / \ __| | __| |_ __ ___ ___ ___ | |_ / _ \| |_ / _` | / _ \ / _` |/ _` | '__/ _ \/ __/ __| | _| (_) | _| (_| | / ___ \ (_| | (_| | | | __/\__ \__ \. |_| \___/|_| \__,_| /_/ \_\__,_|\__,_|_| \___||___/___/
*fofa提取IP脚本 *作者:赵赛赛 *扫描速度快对方可能会屏蔽IP的 """)
Cookie=fofa_token() speed=int(input("请输入扫描速度:")) z=input("请输入要搜索的关键字:") print("你输入的是" + z) coding=base64.b64encode(z.encode('utf-8')).decode("utf-8") cfq_insert_request(Cookie,coding,speed)
|