Create QueryNotify() base class for notifying the caller about the results.

pull/590/head
Christopher K. Hoadley 5 years ago
parent c054712920
commit c07d3967aa

@ -0,0 +1,67 @@
"""Sherlock Notify Module
This module defines the objects for notifying the caller about the
results of queries.
"""
from result import QueryStatus
class QueryNotify():
"""Query Notify Object.
Base class that describes methods available to notify the results of
a query.
It is intended that other classes inherit from this base class and
override the methods to implement specific functionality.
"""
def __init__(self, result=None):
"""Create Query Notify Object.
Contains information about a specific method of notifying the results
of a query.
Keyword Arguments:
self -- This object.
result -- Object of type QueryResult() containing
results for this query.
Return Value:
Nothing.
"""
self.result = result
return
def update(self, result):
"""Notify Update.
Notify method for query result. This method will typically be
overridden by higher level classes that will inherit from it.
Keyword Arguments:
self -- This object.
result -- Object of type QueryResult() containing
results for this query.
Return Value:
Nothing.
"""
self.result = result
return
def __str__(self):
"""Convert Object To String.
Keyword Arguments:
self -- This object.
Return Value:
Nicely formatted string to get information about this object.
"""
result = str(self.result)
return result

@ -26,6 +26,7 @@ from requests_futures.sessions import FuturesSession
from torrequest import TorRequest from torrequest import TorRequest
from result import QueryStatus from result import QueryStatus
from result import QueryResult from result import QueryResult
from notify import QueryNotify
from sites import SitesInformation from sites import SitesInformation
module_name = "Sherlock: Find Usernames Across Social Networks" module_name = "Sherlock: Find Usernames Across Social Networks"
@ -187,7 +188,8 @@ def get_response(request_future, error_type, social_network, verbose=False, colo
return response, error_context, expection_text return response, error_context, expection_text
def sherlock(username, site_data, verbose=False, tor=False, unique_tor=False, def sherlock(username, site_data, query_notify, verbose=False,
tor=False, unique_tor=False,
proxy=None, print_found_only=False, timeout=None, color=True, proxy=None, print_found_only=False, timeout=None, color=True,
print_output=True): print_output=True):
"""Run Sherlock Analysis. """Run Sherlock Analysis.
@ -198,6 +200,9 @@ def sherlock(username, site_data, verbose=False, tor=False, unique_tor=False,
username -- String indicating username that report username -- String indicating username that report
should be created against. should be created against.
site_data -- Dictionary containing all of the site data. site_data -- Dictionary containing all of the site data.
query_notify -- Object with base type of QueryNotify().
This will be used to notify the caller about
query results.
verbose -- Boolean indicating whether to give verbose output. verbose -- Boolean indicating whether to give verbose output.
tor -- Boolean indicating whether to use a tor circuit for the requests. tor -- Boolean indicating whether to use a tor circuit for the requests.
unique_tor -- Boolean indicating whether to use a new tor circuit for each request. unique_tor -- Boolean indicating whether to use a new tor circuit for each request.
@ -280,6 +285,7 @@ def sherlock(username, site_data, verbose=False, tor=False, unique_tor=False,
results_site["url_user"] = "" results_site["url_user"] = ""
results_site['http_status'] = "" results_site['http_status'] = ""
results_site['response_text'] = "" results_site['response_text'] = ""
query_notify.update(results_site['status'])
else: else:
# URL of user on site (if it exists) # URL of user on site (if it exists)
url = net_info["url"].format(username) url = net_info["url"].format(username)
@ -413,6 +419,9 @@ def sherlock(username, site_data, verbose=False, tor=False, unique_tor=False,
f"site '{social_network}'") f"site '{social_network}'")
#Notify caller about results of query.
query_notify.update(result)
if print_output == True: if print_output == True:
#Output to the terminal is desired. #Output to the terminal is desired.
if result.status == QueryStatus.CLAIMED: if result.status == QueryStatus.CLAIMED:
@ -614,12 +623,17 @@ def main():
for site in ranked_sites: for site in ranked_sites:
site_data[site] = site_dataCpy.get(site) site_data[site] = site_dataCpy.get(site)
#Create notify object for query results.
query_notify = QueryNotify()
# Run report on all specified users. # Run report on all specified users.
for username in args.username: for username in args.username:
print() print()
results = sherlock(username, results = sherlock(username,
site_data, site_data,
query_notify,
verbose=args.verbose, verbose=args.verbose,
tor=args.tor, tor=args.tor,
unique_tor=args.unique_tor, unique_tor=args.unique_tor,

@ -9,6 +9,7 @@ import unittest
import sherlock import sherlock
from result import QueryStatus from result import QueryStatus
from result import QueryResult from result import QueryResult
from notify import QueryNotify
from sites import SitesInformation from sites import SitesInformation
import warnings import warnings
@ -49,6 +50,9 @@ class SherlockBaseTest(unittest.TestCase):
except FileNotFoundError: except FileNotFoundError:
self.excluded_sites = [] self.excluded_sites = []
#Create notify object for query results.
self.query_notify = QueryNotify()
self.verbose=False self.verbose=False
self.tor=False self.tor=False
self.unique_tor=False self.unique_tor=False
@ -113,6 +117,7 @@ class SherlockBaseTest(unittest.TestCase):
for username in username_list: for username in username_list:
results = sherlock.sherlock(username, results = sherlock.sherlock(username,
site_data, site_data,
self.query_notify,
verbose=self.verbose, verbose=self.verbose,
tor=self.tor, tor=self.tor,
unique_tor=self.unique_tor, unique_tor=self.unique_tor,

Loading…
Cancel
Save