-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan.py
52 lines (42 loc) · 1.66 KB
/
scan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from config import source_list
from elasticsearch import Elasticsearch
#from multiprocessing.dummy import Pool as ThreadPool
#from redis import Redis
import json
def get_targets():
with open(source_list) as fd:
lines = [line.strip() for line in fd]
return lines
def get_es_info(hosts):
es = Elasticsearch(hosts)
info = es.info()
if not info:
return 0
stats = es.indices.stats()
#print stats
print "***********************************info of elasticsearch server : %s************************************" % hosts[0]
for index in stats["indices"].keys():
indices = dict(es.indices.get(index))
#print "|Index Name\tDoc Count\tType"
print "|",index,"\t",stats["indices"][index]["total"]["docs"]["count"],"\t",indices[index]["mappings"].keys()
#print indices[index]["mappings"].keys()
for type in indices[index]["mappings"].keys():
print "----------------------------------------------%s-------------------------------------------------------" % type
doc = es.search(index=index,doc_type=type)
#print doc
for hits in doc["hits"]["hits"]:
record = dict(hits)
for key in record["_source"].keys():
print key,":",record["_source"][key]
print "\n"
print "****************************************************end*********************************************************"
print "\n\n"
if __name__ == '__main__':
target_list = get_targets()
for ip in target_list:
hosts = list()
hosts.append(ip)
try:
get_es_info(hosts)
except:
pass