FOFA工具思路思考

前言

最近复习挺累的,也不想看视频了,就分享一下之前写的fofa工具,感觉功能挺强大的,就开了一个会员,来玩玩。

简化版

搜索HTTP响应头中含有"thinkphp"关键词的网站和IP
在这里插入图片描述
结果有170361条,肯定看不完的,用脚本爬取

import pyfofa

email = ''  #邮箱
key = ''
search = pyfofa.FofaAPI(email,key)
for host,ip in search.get_data('title="header="thinkphp"',1,"host,ip")['results']:
    print(host,ip)

在这里插入图片描述

看了一下,我只想爬取中国的,那我组合一下语法

#lanxing
#子域名查询
import pyfofa

email = ''  #邮箱
key = ''
search = pyfofa.FofaAPI(email,key)
for host,ip in search.get_data('header="thinkphp" && country="CN"',1,"host,ip")['results']:
    print(host,ip)

如果我想查询C段,也可以,不用爆破,防止测试网站挂了

哈哈哈

#lanxing
#子域名查询
import pyfofa

email = ''  #邮箱
key = ''    
search = pyfofa.FofaAPI(email,key)
for host,ip in search.get_data('domain="baidu.com"',1,"host,ip")['results']:
    print(host,ip)

在这里插入图片描述

优化版

感觉还不满意,就是数据处理问题。

哈哈,上优化代码。

# #lanxing
import os #获取路径

import pyfofa   #fofa登录库
import pandas as pd    #读取csv表格库
import time   #时间库
import csv    #获取到的list数据保存到csv处理库
start=time.time()
def chax():
    email = ''  #y邮箱
    key = ''  #fofa个人key
    search_fofa = input("请输入你要搜索的特征 :")
# print(type(search_fofa))
# print(search_fofa)
# search_fofa = 'domain="baidu.com"'

    search = pyfofa.FofaAPI(email, key)
    re_date = search.get_data(search_fofa, 1, "host,title,country_name,city,ip,port,server,protocol")['results']  #搜索请求,等到想要的数据
# print(re_date)
    print(type(re_date))
    print("*************************开始爬取url***************************")
# for host,title,city in search.get_data('app="TP_LINK-路由器"',1,"host,title,city")['results']:
#     print('标题:' + title, '城市:'+city, 'url :'+host)

    name = ['网站', 'Title','国家', '城市', 'ip地址', 'port','Server','协议']  #csv表格列
    #test = pd.DataFrame(columns=name, data=re_date)
    # print(test)
    # test.to_csv('C:/Users/lanxing/Desktop/fofa_url.csv', encoding='utf-8')
    print("*************************请稍等,正在爬取中**********************")
    with open('fofa1_url.csv','w',encoding='utf-8',newline='') as f:   #写入
        writer = csv.writer(f)
        writer.writerow(name)
        writer.writerows(re_date)





    print("*************************爬取完成***************************")

chax()
end=time.time()
sd=end-start   #end-start,程序运行所需时间
print("******************大佬,fofa信息查询完毕!*************************")
lj = os.path.dirname(__file__) #获取当前目录
print('获取到的数据保存在:'+lj + '目录下面')
print('查询耗时:',str(sd)+'s')   #Python 不允许直接把数字和字符拼接在一起(如果拼在一起就会报标题显示的错误),把数字型的字符串,转化为字符型就可以了,即str()就可以

运行状态
在这里插入图片描述在这里插入图片描述

爬取数据处理

爬虫学习中,遇到数据保存问题,就是学习爬取fofa数据时候,得到的数据数据是list类似,用for打印出太low了,所以就想获取完数据,自动保存到文件中,记录一下。

1.用python创建新的csv文件

使用csv.writer()创建:

#lanxing
#1使用csv.writer()创建
import csv

headers = ['学号','姓名','分数']
rows = [('202001','张三','99'),('202002','李四','96'),('202003','王五','92')]  #头部标题
with open('score.csv','w',encoding='utf8',newline='') as f: #打开csore.csv文件
    writer = csv.writer(f)
    writer.writerow(headers) #头部
    writer.writerows(rows)

在这里插入图片描述
2.用python去读取csv文件数据

#使用pandas.read_csv()读取
import pandas
import pandas as pd
my_matrix = pandas.read_csv('score.csv')
print(my_matrix)
print(my_matrix.shape)
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值