-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathaggregate_hosts.py
37 lines (33 loc) · 992 Bytes
/
aggregate_hosts.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
"""Aggregate hosts data set."""
from censys.search import SearchClient
c = SearchClient()
# The aggregate method constructs a report using a query, an aggregation field, and the
# number of buckets to bin.
report = c.v2.hosts.aggregate(
"services.service_name: HTTP",
"services.port",
num_buckets=5,
)
print(report)
# {
# "total": 987342156,
# "total_omitted": 836949090,
# "potential_deviation": 3965103,
# "buckets": [
# {"key": "80", "count": 58727150},
# {"key": "443", "count": 46716751},
# {"key": "7547", "count": 19185117},
# {"key": "22", "count": 13276559},
# {"key": "30005", "count": 12487489},
# ],
# "query": "services.service_name: HTTP",
# "field": "services.port",
# }
# You can also specify whether to include virtual hosts in the report.
report = c.v2.hosts.aggregate(
"services.service_name: HTTP",
"services.port",
num_buckets=5,
virtual_hosts="INCLUDE",
)
print(report)