-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexample.py
More file actions
60 lines (43 loc) · 1.77 KB
/
Copy pathexample.py
File metadata and controls
60 lines (43 loc) · 1.77 KB
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
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
"""Example usage of the HoneyDB API client.
Credentials are read from environment variables:
export HONEYDB_API_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export HONEYDB_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
"""
import datetime
import json
import os
from honeydb import Client, HoneyDBError
def out(data: object) -> None:
"""Pretty-print JSON data."""
print(json.dumps(data, indent=2, sort_keys=True))
def main() -> None:
api_id = os.environ["HONEYDB_API_ID"]
api_key = os.environ["HONEYDB_API_KEY"]
# The client is a context manager so its connection pool is cleaned up.
with Client(api_id, api_key) as honeydb:
try:
# Bad hosts seen across the honeypot network in the last 24 hours.
out(honeydb.bad_hosts())
# Full context for an IP address (netinfo, threat, history, ...).
out(honeydb.ip("8.8.8.8"))
# Check an IP against known IP lists.
out(honeydb.ipinfo("8.8.8.8"))
out(honeydb.ipinfo_source("tor", "8.8.8.8"))
# Network info lookups do not count against your monthly limit.
out(honeydb.netinfo_as_name(15169))
# Your own sensor data for today.
today = datetime.date.today().isoformat()
out(honeydb.sensor_data_count(today))
out(honeydb.sensor_data(today))
# Manage monitors.
out(honeydb.monitors())
# honeydb.create_monitors([
# {"monitor_type": "asn", "monitor_value": "401120",
# "description": "ASN Example"},
# ])
# honeydb.delete_monitors([122, 123])
except HoneyDBError as error:
print(f"HoneyDB API error: {error}")
if __name__ == "__main__":
main()