fofa资产收集-python爬虫

fofa资产收集-python爬虫无需调用api接口

在使用fofa进行搜索资产时,使用api接口调用进行提取时是有限制的,那提取上限怎么办?一个一个复制出来吗?当然不是,而是需要一个无限制爬取的脚本.

脚本

#coding:utf-8
import sys
#reload(sys)
#sys.setdefaultencoding('utf-8')
import importlib,sys
importlib.reload(sys)
import base64
import requests
from lxml import etree
import time
import threading
threads=[]
time_start = time.time()


def fofa():
    #其中search_data为搜索关键词
    search_data='port="6379"'
    search_data_bs=base64.b64encode(search_data.encode('utf-8'))
    #print (search_data_bs)
    search_data_bs=str(search_data_bs,'UTF-8')
    url='https://fofa.info/result?qbase64='
    headers={
        'cookie':'refresh_token=1;'
                 'fofa_token=你的fofa_token;'
    }
    for yeshu in range(1,5):
        urls=str(url)+search_data_bs+"&page="+str(yeshu)
        #print (urls)
        print("正在提取第"+str(yeshu)+"页数")
        try:

            result=requests.post(urls,headers=headers).content
            #print (result.decode('utf-8'))

            dayi=etree.HTML(result.decode('utf-8'))
            #print(dayi)
            ip_data=dayi.xpath('//span[@class="hsxa-copy-btn hsxa-copy-btn-no-link"]/@data-clipboard-text')
            #print (ip_data)
            ipdata='\n'.join(ip_data)
            #print (ipdata)
            with open(r'ip.txt', 'a+') as f:
                f.write(ipdata+'\n')
                f.close()
        except Exception:
            time.sleep(0.5)
            pass


def ip():
    for ip in open('ip.txt'):
        ip = ip.strip()
        ip = ip.strip('/')
        ip = ip.replace('https://','')
        ip = ip.replace('http://', '')
        data=":"
        if data in ip:
            ip = ip.split(":")
            del ip[-1]
            ip="".join(ip)
            with open(r'ipf.txt', 'a+') as f:
                f.write(ip + '\n')
                f.close()
        else:
            with open(r'ipf.txt', 'a+') as f:
                f.write(ip + '\n')
                f.close()

def qc():

    lines_seen = set()
    outfiile = open('result.txt', 'w', encoding='utf-8')
    f = open('ipf.txt', 'r', encoding='utf-8')
    for line in f:
        if line not in lines_seen:
            outfiile.write(line)
            lines_seen.add(line)

if __name__ == '__main__':
    threads.append(threading.Thread(target=fofa))
    for t in threads:
        t.start()
        t.join()
    ip()
    qc()
    time_end = time.time()
    time_sum = time_end - time_start
    print (" Program run time %s" %time_sum)

脚本使用

在这里插入图片描述
其中search_data填写搜索关键词
123
fofa_token在F12-cookie当中查找复制即可
在这里插入图片描述
后面的页数若是(1,5)那便是提取1页到5页.

结果输出

ip.txt提取的为原始内容结果如下

http://11.74.197.22:9090
http://11.74.197.22:9091
http://11.156.245.220:9090

ipf.txt提取的为原始内容的IP

11.74.197.22
11.74.197.22
11.156.245.220

result.txt是ipf.txt去重后的结果

11.74.197.22
11.156.245.220
  • 5
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值