#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 # Author: f0rsaken

 import getopt
 import requests
 import sys
 import time

 USER = ""
 PASS = ""

 def main():
     try:
         opts, args = getopt.getopt(sys.argv[1:], "hu:p:m:q:l:", ["help", "user=", "pass=", "mode=", "query=", "limit="])
     except getopt.GetoptError as e:
         print("[-] %s" % e)
         usage()
         sys.exit(2)

     username = USER
     password = PASS
     mode = "host"
     query = ""
     limit = 2048

     for o, a in opts:
         if o in ("-h", "--help"):
             usage()
             sys.exit()
         elif o in ("-u", "--user"):
             username = a
         elif o in ("-p", "--pass"):
             password = a
         elif o in ("-m", "--mode"):
             if a in ("host", "web"):
                 mode = a
             else:
                 print("[-] Unknown Mode!")
                 usage()
                 sys.exit(2)
         elif o in ("-q", "--query"):
             query = a
         elif o in ("-l", "--limit"):
             try:
                 limit = int(a)
             except ValueError as e:
                 print("[-] %s" % e)
                 usage()
                 sys.exit(2)
         else:
             pass

     if not query:
         print("[-] Query Keyword Not Found!")
         usage()
         sys.exit(2)

     print("[!] Mode: %s" % mode)
     print("[!] Query: %s" % query)
     print("[!] Limit: %s" % limit)

     try:
         choice = raw_input("Start Query? [Y/n] ")
     except NameError as e:
         choice = input("Start Query? [Y/n] ")

     if choice.lower() == "n":
         sys.exit()

     authorization = get_authorization(username, password)
     if not authorization:
         sys.exit(1)

     resources_info = get_resources_info(authorization)
     if not resources_info:
         sys.exit(1)
     else:
         print("[*] Plan: %s" % resources_info["plan"])
         print("[*] Resources: Host %s Web %s" % (resources_info["resources"]["host-search"], resources_info["resources"]["web-search"]))

     result = list()
     page = 1
     while page <= limit:
         temp = search(authorization, mode, query, str(page))
         if not temp:
             break
         result.extend(extract(mode, temp))
         print("Download Page: %s" % page)
         page += 1
     result = set(result)

     log = "ZoomEye_" + str(time.time()) + ".txt"
     with open(log, "w") as f:
         f.writelines(result)

     print("Please Check The %s" % log)

 def usage():
     print("Usage: python %s [options]" % sys.argv[0])
     print("")
     print("Options:")
     print("  -h, --help                        Show Help Message And Exit")
     print("  -u USER, --user=USER              ZoomEye E-Mail")
     print("  -p PASS, --pass=PASS              ZoomEye Password")
     print("  -m MODE, --mode=MODE              host || web (Default: host)")
     print("  -q QUERY, --query=QUERY           Query Keyword")
     print("  -l LIMIT, --limit=LIMIT           Page Limit (Default: 2048)")

 def get_authorization(username, password):
     authorization = dict()
     access_token = get_access_token(username, password)
     if access_token:
         authorization["Authorization"] = "JWT " + access_token["access_token"]
     else:
         pass
     return authorization

 def get_access_token(username, password):
     try:
         r = requests.post("https://api.zoomeye.org/user/login", json={"username": username, "password": password})
     except requests.RequestException as e:
         print("[-] %s" % e)
         print("[-] Get Access Token Failed!")
     else:
         if r.status_code == requests.codes.ok:
             return r.json()
         else:
             print("[-] %s %s \n[-] %s" % (r.status_code, r.json()["error"], r.json()["message"]))
             print("[-] Get Access Token Failed!")

 def get_resources_info(authorization):
     try:
         r = requests.get("https://api.zoomeye.org/resources-info", headers=authorization)
     except requests.RequestException as e:
         print("[-] %s" % e)
         print("[-] Get Resources Info Failed!")
     else:
         if r.status_code == requests.codes.ok:
             return r.json()
         else:
             print("[-] %s %s \n[-] %s" % (r.status_code, r.json()["error"], r.json()["message"]))
             print("[-] Get Resources Info Failed!")

 "):
     try:
         url = "https://api.zoomeye.org/" + mode + "/search?query=" + query + "&page=" + page
         print("GET %s" % url)
         r = requests.get(url, headers=authorization)
     except requests.RequestException as e:
         print("[-] %s" % e)
         print("[-] %s Search Failed!" % mode.capitalize())
     else:
         if r.status_code == requests.codes.ok:
             return r.json()
         else:
             print("[-] %s %s \n[-] %s" % (r.status_code, r.json()["error"], r.json()["message"]))
             print("[-] %s Search Failed!" % mode.capitalize())

 def extract(mode, temp):
     result = list()
     if mode == "host":
         for line in temp["matches"]:
             result.append(line["ip"] + ":" + str(line["portinfo"]["port"]) + "\n")
     else:
         for line in temp["matches"]:
             result.append(line["site"] + "\n")
     return result

 if __name__ == "__main__":
     main()

ZoomEye 钟馗之眼 搜索工具 基于API的更多相关文章

  1. ZoomEye(钟馗之眼)搜索技巧记录:

    做个记录方便查看 钟馗之眼: 指定搜索的组件:    app:组件名称    ver:组件版本    例:搜索 apache组件版本2.4:app:apache var:2.4指定搜素的端口:     ...

  2. 基于文本图形(ncurses)的文本搜索工具 ncgrep

    背景 作为一个VIM党,日常工作开发中,会经常利用grep进行关键词搜索,以快速定位到文件.如图: 利用grep进行文本搜索 但是,这一过程会有两个效率问题: 展示的结果无法进行直接交互,需要手动粘贴 ...

  3. 揭开Faiss的面纱 探究Facebook相似性搜索工具的原理

    https://www.leiphone.com/news/201703/84gDbSOgJcxiC3DW.html 本月初雷锋网报道,Facebook 开源了 AI 相似性搜索工具 Faiss.而在 ...

  4. 文件快速搜索工具-Everything的使用(转)

    首先它是一款基于名称实时定位文件和目录的搜索工具,有以下几个优点: 快速文件索引 快速文件搜索 较低资源占用 轻松分享文件索引 实时跟踪文件更新 通过使用everything小工具,可以提高我们的工作 ...

  5. Everything:速度最快的文件名搜索工具(Linux版本) 转

    Everything是windows的一个快速搜索工具. 基本上转移到Linux上来后,没有怎么用过. 一直在用Gnome-Do,感觉还可以. 这个程序只是用来练习wxPython用的,目前还只是一个 ...

  6. 文件搜索工具everything

    Everything是voidtools开发的一款文件搜索工具,官网描述为“基于名称实时定位文件和目录(Locate files and folders by name instantly) (“Ev ...

  7. Python开发环境Wing IDE搜索工具介绍

    Wing IDE编辑器的搜索工具提供了一个基于友好GUI的搜索和替换工具. 某些情况下搜索可能会跨越整个文件,也有可能被限制到当前所选择的区域:可以区分大小写,也可以设置为不区分:可以被限制为只匹配整 ...

  8. [转帖]推荐一款比 Find 快 10 倍的搜索工具 FD

    推荐一款比 Find 快 10 倍的搜索工具 FD https://www.hi-linux.com/posts/15017.html 试了下 很好用呢. Posted by Mike on 2018 ...

  9. centos locate搜索工具

    locate搜索工具 [root@localhost ~]# yum install mlocate [root@localhost ~]# locate passwd locate: can not ...

随机推荐

  1. 对日期 ,和 master.dbo.spt_values 表操作

    if object_id('tempdb..#xs') is not null drop table #xs; ), date datetime, sale float) insert into #x ...

  2. Android常用组件之ListView

    使用ListAdapter是ListView的适配器. 使用ListView.setAdapter()方法来设置ListView的适配器. 简单的使用 adapter = new ArrayAdapt ...

  3. GitHub上值得关注的iOS开源项目

    1.AFNetworking地址:https://github.com/AFNetworking/AFNetworking用于网络请求 2.JSONKit地址:https://github.com/j ...

  4. 通过akRegionCode找到对应的程序

    在Oracle EBS中,有一些程序是从上一个版本的Web开发框架(AK)转成OAF的,而这部分程序定义的功能与一般的OAF页面不同,OAF页面使用 OA.jsp?page=/oracle/apps/ ...

  5. Linux 双网卡绑定

    Linux 双网卡绑定 Linux 双网卡绑定双网卡绑定的常用模式:mode1:active-backup 模式,即主备模式.mode0:round-broin 模式,即负载均衡模式(需要交换机配置聚 ...

  6. rewrite

    http://www.iis.net/downloads/microsoft/url-rewrite

  7. CI模板加载css和js

    1.需求 ci无法加载css和js文件. 2.解决 删除..htaccess文件. 在config目录下配置base_url,并传给页面 $base_url = $this->config-&g ...

  8. 项目vue2.0仿外卖APP(六)

    goods 商品列表页开发 布局编写 除了商品之外还有购物车,还有个详情页,挺复杂的. 两栏布局:左侧固定宽度,右侧自适应,还是用flex. 因为内容可能会超过手机高度,超过就隐藏.左右两侧的内容是可 ...

  9. SQL分组多列统计(GROUP BY后按条件分列统计)

    as tjsl from fyxx group by zt,whbmbh end) as ybhsl from fyxx group by whbmbh 下面是摘自别人的博客 最近遇到一个问题,需要对 ...

  10. leetcode一些常用函数

    6移位操作 “>> 右移,高位补符号位” 这里右移一位表示除2“>>> 无符号右移,高位补0”: 与>>类似“<< 左移” 左移一位表示乘2,二位 ...