| 1 |
"""Aggregate hosts data set.""" |
| 2 |
|
| 3 |
from censys.search import SearchClient |
| 4 |
|
| 5 |
c = SearchClient() |
| 6 |
|
| 7 |
# The aggregate method constructs a report using a query, an aggregation field, and the |
| 8 |
# number of buckets to bin. |
| 9 |
report = c.v2.hosts.aggregate( |
| 10 |
"services.service_name: HTTP", |
| 11 |
"services.port", |
| 12 |
num_buckets=5, |
| 13 |
) |
| 14 |
print(report) |
| 15 |
# { |
| 16 |
# "total": 987342156, |
| 17 |
# "total_omitted": 836949090, |
| 18 |
# "potential_deviation": 3965103, |
| 19 |
# "buckets": [ |
| 20 |
# {"key": "80", "count": 58727150}, |
| 21 |
# {"key": "443", "count": 46716751}, |
| 22 |
# {"key": "7547", "count": 19185117}, |
| 23 |
# {"key": "22", "count": 13276559}, |
| 24 |
# {"key": "30005", "count": 12487489}, |
| 25 |
# ], |
| 26 |
# "query": "services.service_name: HTTP", |
| 27 |
# "field": "services.port", |
| 28 |
# } |
| 29 |
|
| 30 |
# You can also specify whether to include virtual hosts in the report. |
| 31 |
report = c.v2.hosts.aggregate( |
| 32 |
"services.service_name: HTTP", |
| 33 |
"services.port", |
| 34 |
num_buckets=5, |
| 35 |
virtual_hosts="INCLUDE", |
| 36 |
) |
| 37 |
print(report) |