Created
February 28, 2019 20:38
-
-
Save igama/c146f766ad13ed0b61ecc1a7468adfe8 to your computer and use it in GitHub Desktop.
Get a daily update of the IPS, Networks, ASNs you are interested in using BinaryEdge data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# Example Script | |
# Get a daily update of what you are interested in. | |
# What was detected in the last 24hours | |
# | |
# For detail on the fields for each message type please check https://docs.binaryedge.io/modules/ | |
from pybinaryedge import BinaryEdge | |
import math | |
from datetime import datetime, timedelta | |
BE_API_KEY="YOUR_API_TOKEN" | |
#IPs and CIDRS | |
NETWORKS=["192.168.1.1","192.168.2.1/24"] | |
#Autonomous System Numbers | |
ASN=["1234","5678"] | |
#HOURS | |
TIMEFRAME=24 | |
def get_hosts_details(client, search): | |
response = client.host_search(search) | |
pages = math.ceil(int(response['total']) / 20) + 1 | |
print(search) | |
print(pages) | |
for i in range(1, pages): | |
for event in client.host_search(search, i)['events']: | |
print(event) | |
if __name__ == "__main__": | |
client = BinaryEdge(BE_API_KEY) | |
time_now = datetime.now() | |
timeframe_ago = time_now - timedelta(hours=TIMEFRAME) | |
for network in NETWORKS: | |
search = 'ip:"%s" AND created_at:[%s TO %s]' % (network,timeframe_ago.strftime('%Y-%m-%dT%H:%M'),time_now.strftime('%Y-%m-%dT%H:%M')) | |
get_hosts_details(client, search) | |
for asn in ASN: | |
search = 'asn:%s AND created_at:[%s TO %s]' % (asn,timeframe_ago.strftime('%Y-%m-%dT%H:%M'),time_now.strftime('%Y-%m-%dT%H:%M')) | |
get_hosts_details(client, search) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment