zabbix批量检测以及zoomeye搜索

zabbix批量检测

0x11 利用zoomeye批量获取IP

zoomeye开放了API之后一直想用它批量一次,这次zabbix爆出来之后,闲的没事就找了一个批量拿IP的zoomeye脚本,现在分享出来.

 1 #coding: utf-8
 2 '''
 3 author : xnianq
 4 date : 2016-08-25
 5 '''
 6 import os
 7 import requests
 8 import json
 9 access_token=''
10 ip_list=[]
11 def login():
12     """
13      输入帐号密码,进行登录操作
14     :return:  访问口令 access_token
15     """
16     user = raw_input('[-] input : username :')
17     passwd = raw_input('[-] input : passwd :')
18     data = {
19         'username' : user,
20         'password' : passwd
21     }
22     data_encoded = json.dumps(data)
23     try:
24         r = requests.post(url="https://api.zoomeye.org/user/login",data=data_encoded)
25         r_decode = json.loads(r.text)
26         global access_token
27         access_token = r_decode['access_token']
28     except Exception,e:
29         print '[-] info : username or password seems wrong,please try again .'
30         exit()
31 def saveStrToFile(file,str):
32     """
33     将字符串写入文本中
34     :param file:
35     :param str:
36     :return:
37     """
38     with open(file,'w') as output:
39         output.write(str)
40 def saveListToFile(file,list):
41     """
42     将列表逐行写入文件中
43     :param file:
44     :param list:
45     :return:
46     """
47     s = '
'.join(list)
48     with open(file,'w') as output:
49         output.write(s)
50 def apiTest():
51     """
52     进行Api测试
53     :return:
54     """
55     page = 1
56     global access_token
57     with open('access_token.txt','r') as input:
58         access_token = input.read()
59     headers = {
60         'Authorization' : 'JWT ' + access_token,
61     }
62     while(True):
63         try:
64             r = requests.get(url = 'https://api.zoomeye.org/host/search?query=“zabbix”&page='+str(page),headers=headers)
65             r_decoded = json.loads(r.text)
66             for x in r_decoded['matches']:
67                 print x['ip']
68                 ip_list.append(x['ip'])
69             print '[-] info : count ' + str(page*10)
70         except Exception,e:
71             if str(e.message) == 'matches':
72                 print '[-] info : account was break ,excceeding the max limitations'
73                 break
74             else:
75                 print '[-] info :' + str(e.message)
76         else:
77             if page == 100 :
78                 break
79             page +=1
80 def main():
81     if not os.path.isfile('access_token.txt'):
82         print '[-] info : access_toke is not exists,please login'
83         login()
84         saveStrToFile('access_token.txt',access_token)
85     apiTest()
86     saveListToFile('ip_list.txt',ip_list)
87 if __name__ == '__main__':
88     main()
原文地址:https://www.cnblogs.com/cbreeze/p/5951379.html