I have a program that scans Google for links, it verifies how many links you've found and then tries to find a success right for your search:
def check_urls_for_queries(self):
""" The returned URLS will be run through a query regex to see if
they have a query parameter.
http://google.com <- False
http://example.com/php?id=2 <- True
"""
filename = settings.create_random_filename()
print("File being saved to: {}".format(filename))
with open("{}\\{}.txt".format(settings.DORK_SCAN_RESULTS_PATH, filename),
"a+") as results:
for url in self.connect_to_search_engine():
match = settings.QUERY_REGEX.match(url) # Match by regex for anything
# that has a ?=<PARAM> in it
if match:
results.write(url + "\n")
amount_of_urls = len(open(settings.DORK_SCAN_RESULTS_PATH + "\\" + filename
+ ".txt", 'r').readlines())
return("\nFound a total of {} usable links with query (GET) parameters, urls"
" have been saved to {}\\{}.txt. This Dork has a success rate of {}%".
format(amount_of_urls, settings.DORK_SCAN_RESULTS_PATH, filename,
self.success_rate[amount_of_urls]
if amount_of_urls in self.success_rate.keys() else
'Unknown success rate'))
What I would like to do is create the success rate using a range per dict key:
success_rate = {
range(1, 10): 10, range(11, 20): 20, range(21, 30): 30,
range(31, 40): 40, range(41, 50): 50, range(51, 60): 60,
range(61, 70): 70, range(71, 80): 80, range(81, 90): 90,
range(91, 100): 100
}
However obviously this doesn't work because lists are not hashable objects:
Traceback (most recent call last):
File "tool.py", line 2, in <module>
from lib.core import BANNER
File "C:\Users\Documents\bin\python\pybelt\lib\core\__init__.py", line 1, in <module>
from dork_check import DorkScanner
File "C:\Users\Documents\bin\python\pybelt\lib\core\dork_check\__init__.py", line 1, in <module>
from dorks import DorkScanner
File "C:\Users\\Documents\bin\python\pybelt\lib\core\dork_check\dorks.py", line 6, in <module>
class DorkScanner(object):
File "C:\Users\Documents\bin\python\pybelt\lib\core\dork_check\dorks.py", line 11, in DorkScanner
range(1, 10): 10, range(11, 20): 20, range(21, 30): 30,
TypeError: unhashable type: 'list'
Is there a way I could use a range for a dict key to save myself from having to make a key from 1 – 100?