Skip to content

Instantly share code, notes, and snippets.

@superducktoes
Created November 1, 2022 22:23
Show Gist options
  • Save superducktoes/ba989b291c7369b69713bf3011092d9d to your computer and use it in GitHub Desktop.
Save superducktoes/ba989b291c7369b69713bf3011092d9d to your computer and use it in GitHub Desktop.
Query GreyNoise without the GN SDK
import requests
import json
GN_API_KEY = ""
GN_QUERY = "last_seen:1d classification:malicious"
GN_QUERY_URL = "https://api.greynoise.io/v2/experimental/gnql"
HEADERS = {
"accept": "application/json",
"key": GN_API_KEY
}
gn_ip_list = []
continue_loop = True
PARAMS = {
"query": GN_QUERY,
"size": "10000",
"scroll": ""
}
while continue_loop:
# make the request to GN
r = requests.get(GN_QUERY_URL, headers=HEADERS, params=PARAMS).json()
for i in r["data"]:
gn_ip_list.append(i["ip"])
# if there's more than 10,000 results add the scoll key to the params and keep requesting
if("scroll" in r):
PARAMS["scroll"] = r["scroll"]
else:
continue_loop = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment