Skip to content

Commit a3c560a

Browse files
Merge pull request #106 from ChuckWoodraska/ID-1476
ID-1476 Added new method so that Iris Enrich can be used in the cli
2 parents b20f2d4 + 538ef48 commit a3c560a

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

domaintools/api.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,35 @@ def iris_enrich(self, *domains, **kwargs):
292292
return self._results('iris-enrich', '/v1/iris-enrich/', domain=domains, data_updated_after=data_updated_after,
293293
items_path=('results',), **kwargs)
294294

295+
def iris_enrich_cli(self, domains=None, **kwargs):
296+
"""Returns back enriched data related to the specified domains using our Iris Enrich service.
297+
This is a CLI version of the iris_enrich method to help maintain backwards compatibility.
298+
299+
api.iris_enrich(['domaintools.com', 'google.com'])
300+
301+
api.iris_enrich(DOMAIN_LIST)['results_count'] Returns the number of results
302+
api.iris_enrich(DOMAIN_LIST)['missing_domains'] Returns any domains that we were unable to
303+
retrieve enrichment data for
304+
api.iris_enrich(DOMAIN_LIST)['limit_exceeded'] Returns True if you've exceeded your API usage
305+
306+
for enrichment in api.iris_enrich(DOMAIN_LIST): # Enables looping over all returned enriched domains
307+
308+
for example:
309+
enrich_domains = ['google.com', 'amazon.com']
310+
assert api.iris_enrich(*enrich_domains)['missing_domains'] == []
311+
"""
312+
if not domains:
313+
raise ValueError('One or more domains to enrich must be provided')
314+
315+
if isinstance(domains, (list, tuple)):
316+
domains = ','.join(domains)
317+
data_updated_after = kwargs.get('data_updated_after', None)
318+
if hasattr(data_updated_after, 'strftime'):
319+
data_updated_after = data_updated_after.strftime('%Y-%m-%d')
320+
321+
return self._results('iris-enrich', '/v1/iris-enrich/', domain=domains, data_updated_after=data_updated_after,
322+
items_path=('results',), **kwargs)
323+
295324
def iris_investigate(self, domains=None, data_updated_after=None, expiration_date=None,
296325
create_date=None, active=None, search_hash=None, **kwargs):
297326
"""Returns back a list of domains based on the provided filters.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
interactions:
2+
- request:
3+
body: app_name=python_wrapper&app_version=0.6.2&domain=google.com
4+
headers:
5+
accept:
6+
- '*/*'
7+
accept-encoding:
8+
- gzip, deflate
9+
connection:
10+
- keep-alive
11+
content-length:
12+
- '203'
13+
content-type:
14+
- application/x-www-form-urlencoded
15+
host:
16+
- api.domaintools.com
17+
user-agent:
18+
- python-httpx/0.22.0
19+
method: POST
20+
uri: https://api.domaintools.com/v1/iris-enrich/
21+
response:
22+
content: '{"response":{"limit_exceeded":false,"message":"Enjoy your data.","results_count":1,"results":[{"domain":"google.com","whois_url":"https:\/\/whois.domaintools.com\/google.com","adsense":{"value":""},"alexa":1,"popularity_rank":1,"active":true,"google_analytics":{"value":""},"admin_contact":{"name":{"value":""},"org":{"value":"Google
23+
LLC"},"street":{"value":""},"city":{"value":""},"state":{"value":"CA"},"postal":{"value":""},"country":{"value":"us"},"phone":{"value":""},"fax":{"value":""},"email":[{"value":"select
24+
request email form at https:\/\/domains.markmonitor.com\/whois\/google.com"}]},"billing_contact":{"name":{"value":""},"org":{"value":""},"street":{"value":""},"city":{"value":""},"state":{"value":""},"postal":{"value":""},"country":{"value":""},"phone":{"value":""},"fax":{"value":""},"email":[]},"registrant_contact":{"name":{"value":""},"org":{"value":"Google
25+
LLC"},"street":{"value":""},"city":{"value":""},"state":{"value":"CA"},"postal":{"value":""},"country":{"value":"us"},"phone":{"value":""},"fax":{"value":""},"email":[{"value":"select
26+
request email form at https:\/\/domains.markmonitor.com\/whois\/google.com"}]},"technical_contact":{"name":{"value":""},"org":{"value":"Google
27+
LLC"},"street":{"value":""},"city":{"value":""},"state":{"value":"CA"},"postal":{"value":""},"country":{"value":"us"},"phone":{"value":""},"fax":{"value":""},"email":[{"value":"select
28+
request email form at https:\/\/domains.markmonitor.com\/whois\/google.com"}]},"create_date":{"value":"1997-09-15"},"expiration_date":{"value":"2028-09-14"},"email_domain":[{"value":"markmonitor.com"},{"value":"google.com"}],"soa_email":[{"value":"[email protected]"}],"ssl_email":[],"additional_whois_email":[{"value":"[email protected]"},{"value":"[email protected]"}],"ip":[{"address":{"value":"142.250.217.78"},"asn":[{"value":15169}],"country_code":{"value":"US"},"isp":{"value":"Google"}},{"address":{"value":"142.250.69.196"},"asn":[{"value":15169}],"country_code":{"value":"US"},"isp":{"value":"Google"}}],"mx":[{"host":{"value":"smtp.google.com"},"domain":{"value":"google.com"},"ip":[{"value":"74.125.195.27"},{"value":"74.125.135.26"},{"value":"74.125.195.26"},{"value":"74.125.142.26"},{"value":"74.125.142.27"}],"priority":10}],"name_server":[{"host":{"value":"ns4.google.com"},"domain":{"value":"google.com"},"ip":[{"value":"216.239.38.10"}]},{"host":{"value":"ns2.google.com"},"domain":{"value":"google.com"},"ip":[{"value":"216.239.34.10"}]},{"host":{"value":"ns1.google.com"},"domain":{"value":"google.com"},"ip":[{"value":"216.239.32.10"}]},{"host":{"value":"ns3.google.com"},"domain":{"value":"google.com"},"ip":[{"value":"216.239.36.10"}]}],"domain_risk":{"risk_score":0,"components":[{"name":"zerolist","risk_score":0},{"name":"threat_profile","risk_score":0},{"name":"threat_profile_malware","risk_score":0},{"name":"threat_profile_phishing","risk_score":0},{"name":"threat_profile_spam","risk_score":0}]},"redirect":{"value":""},"redirect_domain":{"value":""},"registrant_name":{"value":""},"registrant_org":{"value":"Google
29+
LLC"},"registrar":{"value":"MarkMonitor, Inc."},"registrar_status":["clientdeleteprohibited","clienttransferprohibited","clientupdateprohibited","serverdeleteprohibited","servertransferprohibited","serverupdateprohibited"],"spf_info":"","ssl_info":[{"hash":{"value":"fcebe5bb73f9541e544eb1a784ada0b35060412b"},"subject":{"value":"CN=www.google.com"},"organization":{"value":""},"email":[]}],"tld":"com","website_response":200,"data_updated_timestamp":"2022-06-15T08:44:07.327000","tags":[]}],"missing_domains":[]}}'
30+
headers:
31+
Content-Encoding:
32+
- gzip
33+
Content-Type:
34+
- application/json;charset=utf-8
35+
Date:
36+
- Wed, 15 Jun 2022 15:03:07 GMT
37+
Transfer-Encoding:
38+
- chunked
39+
Vary:
40+
- Accept-Encoding
41+
X-TIME:
42+
- '68140'
43+
http_version: HTTP/1.1
44+
status_code: 200
45+
version: 1

tests/test_api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,17 @@ def test_iris_enrich():
408408
assert result['domain'] == 'google.com'
409409

410410

411+
@vcr.use_cassette
412+
def test_iris_enrich_cli():
413+
with pytest.raises(ValueError):
414+
api.iris_enrich()
415+
416+
enriched_data = api.iris_enrich('google.com')
417+
assert enriched_data['results_count']
418+
for result in enriched_data:
419+
assert result['domain'] == 'google.com'
420+
421+
411422
@vcr.use_cassette
412423
def test_iris_investigate():
413424
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)