#!/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. Git学习笔记

    1.第一次提交文件的过程:     1)创建代码库:cd到要作为git代码库的文件夹下,执行git init命令.     2)设置邮箱和用户名:设置后才可提交代码,git config user.e ...

  2. C# 反射研究

    概念 反射这东西,对于我这种小白,听起来总是觉得好大上的. 当初理解它费了一点时间,后来看了一句话,突然恍然大悟,“反射就跟B超一样,我们在不剖开人体的情况下想看清楚内部情况, 我们就通过发射超声波, ...

  3. [Computational Advertising] 计算广告学笔记之基础概念

    因为工作需要,最近一直在关注计算广告学的内容.作为一个新手,学习计算广告学还是建议先看一下刘鹏老师在师徒网的教程<计算广告学>. 有关刘鹏老师的个人介绍:刘鹏现任360商业产品首席架构师, ...

  4. laravel5 安装笔记

    1.环境更新 apt-get update apt-get install php5-cli apt-get install curl 2. Composer安装 curl -sS https://g ...

  5. applicationContext.xml的基本配置文件

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

  6. Sicily 1153: 马的周游问题(DFS+剪枝)

    这道题没有找到一条回路,所以不能跟1152一样用数组储存后输出.我采用的方法是DFS加剪枝,直接DFS搜索会超时,优化的方法是在搜索是优先走出度小的路径,比如move1和move2都可以走,但是如走了 ...

  7. YII2之 Scenario

    使用方法 // scenario is set as a property $model = new User; $model->scenario = User::SCENARIO_SHOW; ...

  8. idea开发工具破解地址

    链接失效可以使用激活码.激活码不需要联网也可以开发. idea 在注册时选择 License server ,填http://idea.iteblog.com/key.php ,然后点击激活. 激活码 ...

  9. django tag

    官方文档:https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/#simple-tags stackoverflow de ...

  10. 【Oracle】Oracle日期格式详解

    本文章没有经过验证,纯属使用CV大法.感谢原创的大牛. to_date("要转换的字符串","转换的格式")   两个参数的格式必须匹配,否则会报错. 即按照第 ...