前言

我先说关于我投稿转正的文章一打开浏览器崩溃的问题(因为太长) 你们可以试试...(当时我还和阿皮在那里笑心想这算BUG吗),应该是圈子某个JS的问题,当我禁用JS的时候可以正常浏览,一点没问题,希望团长可以优化下。

正题

Zoomeye是干嘛的 大家都懂我也不在这里解释了, 去年tools我记得有人写出来过,但是后来Zoomeye更新了,也就没用了。

采集示列

56465465456545.png

# -*- coding: utf-8 -*-
# @Time    : 2019-07-04 01:35
# @Author  : Coder
# @FileName: zoomeye_get_url.py
# @Software: Submie

import os
import requests
import json
import sys

access_token = ''
ip_list = []
#你想要搜索的
query = input('[+] input : the data you want to search :')

def login():
    """
        输入用户名密码 进行登录操作
    :return: 访问口令 access_token
    """
    user = input('[+] input : username :')
    passwd = input('[+] input : password :')
    # 要搜索的字段
    data = {
        'username' : user,
        'password' : passwd
    }
    data_encoded = json.dumps(data)  # dumps 将 python 对象转换成 json 字符串
    try:
        r = requests.post(url = 'https://api.zoomeye.org/user/login',data = data_encoded)
        r_decoded = json.loads(r.text) # loads() 将 json 字符串转换成 python 对象
        global access_token
        access_token = r_decoded['access_token']
    except Exception as e:
        print('[+] info : username or password is wrong, please try again ')
        exit()

def saveStrToFile(file,str):
    """
        将字符串写入文件中
    :return:
    """
    with open(file,'w') as output:
        output.write(str)

def saveListToFile(file,list):
    """
        将列表逐行写入文件中
    :return:
    """
    s = '\n'.join(list)
    with open(file,'w') as output:
        output.write(s)

def apiTest():
    """
        进行 api 使用测试
    :return:
    """
    page = 1
    global access_token
    with open('access_token.txt','r') as input:
        access_token = input.read()
    # 将 token 格式化并添加到 HTTP Header 中
    headers = {
        'Authorization' : 'JWT ' + access_token,
    }
    # print(headers
    while(True):
        try:
            # query参数
            url = 'https://api.zoomeye.org/host/search?query={}&facet=app,os&page='.format(query)
            r = requests.get(url = url + str(page),headers = headers)
            r_decoded = json.loads(r.text)
            # print(r_decoded
            # print(r_decoded['total']
            for x in r_decoded['matches']:
                print(x['ip'])
                ip_list.append('http://'+x['ip'])
            print('[+] info : count ' + str(page * 10))

        except Exception as e:
            # 若搜索请求超过 API 允许的最大条目限制 或者 全部搜索结束,则终止请求
            if str(e.message) == 'matches':
                print('[-] info : account was break, excceeding the max limitations')
                break
            else:
                print( '[+] info : ' + str(e.message))
        else:
            # 修改查询的页数
            if page == 10:
                break
            page += 1

def main():
    # 访问口令文件不存在则进行登录操作
    if not os.path.isfile('access_token.txt'):
        print('[-] info : access_token file is not exist, please login')
        login()
        saveStrToFile('access_token.txt',access_token)

    apiTest()
    saveListToFile('ip_list.txt',ip_list)

if __name__ == '__main__':
    main()

标签: none

添加新评论