Last active
October 25, 2017 01:19
-
-
Save jdembowski/4a260f3daad2203f323227d501dabb75 to your computer and use it in GitHub Desktop.
Read all the domains in an Umbrella Enforcement API integration
This file contains 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/python | |
import urllib2, json, fileinput, sys, os, time | |
from datetime import datetime | |
from time import gmtime, strftime | |
# Read key, single line | |
with open('api-key.txt', 'r') as k: | |
api_key = k.read().rstrip() | |
def confirmEnforcement(indomains=[]): | |
# This function takes a list of domains as an argument and compares that | |
# to all the domains in an Umbrella Enforcement API integration | |
# The API returns a maximum of 200 domains at a time. For 28,000 domains | |
# it takes almost 2 minutes. | |
# The function returns an array: | |
# All domains found:True or False, | |
# domains in the Enforcement API integration list, | |
# Number of domains in the Enforcement API integration, | |
# time it took in seconds | |
next='https://s-platform.api.opendns.com/1.0/domains?customerKey='+api_key+'&limit=200' | |
start_time = time.time() | |
page=1 | |
domains=[] | |
while next != False: | |
req = urllib2.Request(url=next) | |
f = urllib2.urlopen(req) | |
result = json.loads(f.read()) | |
for i in range(len(result['data'])): | |
domains.append(result['data'][i]['name']) | |
next=result['meta']['next'] | |
page += 1 | |
time_elapsed=time.time() - start_time | |
output = { | |
'AllDomains': all(x in domains for x in indomains), | |
'DomainList': domains, | |
'NoOfDomains': len(domains), | |
'TotalTime': time_elapsed | |
} | |
return output | |
test=['google.com', 'cnn.com', 'dembowski.net'] | |
print 'Getting domains in Enforcement API key' | |
x = confirmEnforcement(test) | |
print 'That took', x['TotalTime'], 'seconds.' | |
print 'All Domains?', x['AllDomains'] | |
print 'No of Domains:',x['NoOfDomains'] | |
print 'Domains returned:' | |
for domain in x['DomainList']: | |
print domain | |
print 'Getting just the domains for tha API key' | |
y=confirmEnforcement() | |
print 'That took', y['TotalTime'], 'seconds.' | |
print 'No of Domains:',y['NoOfDomains'] | |
print 'Domains returned:' | |
for domain in y['DomainList']: | |
print domain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment