Skip to content

Instantly share code, notes, and snippets.

@ransford
Created April 30, 2016 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ransford/0242b4321e422127c909b80e98610778 to your computer and use it in GitHub Desktop.
Save ransford/0242b4321e422127c909b80e98610778 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""Quickly and dirtily get JBoss X-Powered-By header contents
from the Censys API.
Usage: python censys_jboss.py > censys_jboss.txt"""
import os
import sys
import json
import requests
API_URL = "https://www.censys.io/api/v1"
# get the following from https://censys.io/account
UID = os.environ['CENSYS_UID']
SECRET = os.environ['CENSYS_SECRET']
def go():
pagenum = 1
npages = 99999999
while pagenum < npages:
payload = dict(query='80.http.get.headers.x_powered_by: JBoss',
fields=['80.http.get.headers.x_powered_by'],
page=pagenum)
res = requests.post(API_URL + "/search/ipv4",
auth=(UID, SECRET),
json=payload)
if res.status_code != 200:
print "error occurred: %d" % res.status_code
sys.exit(1)
j = res.json()
if pagenum == 1:
print '# %s' % j['metadata']
npages = j['metadata']['pages']
if j["status"] != "ok":
print "API query status is not 'ok': %s" % j["status"]
sys.exit(2)
for result in j["results"]:
print result['80.http.get.headers.x_powered_by'][0]
pagenum += 1
if __name__ == '__main__':
go()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment