From b04da59879b7d4edce9de24b8310bef35faeddb2 Mon Sep 17 00:00:00 2001 From: Hossam Al-Dokkani Date: Sat, 21 Jul 2018 14:36:52 +0200 Subject: [PATCH 1/4] Remove pointless-string-statement --- modules/getemails.py | 2 +- modules/getweblinks.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/getemails.py b/modules/getemails.py index e81715b3..bd9f84ca 100644 --- a/modules/getemails.py +++ b/modules/getemails.py @@ -22,7 +22,7 @@ def getMails(soup): emails = get_urls_from_page(soup, email=True) - """Pretty print output as below""" + # Pretty print output as below print('') print(b_colors.OKGREEN+'Mails Found - '+b_colors.ENDC+str(len(emails))) print('-------------------------------') diff --git a/modules/getweblinks.py b/modules/getweblinks.py index 7108663c..79b7883d 100644 --- a/modules/getweblinks.py +++ b/modules/getweblinks.py @@ -28,7 +28,7 @@ def get_links(soup, ext=False, live=False): b_colors = Bcolors() if isinstance(soup, BeautifulSoup): websites = get_urls_from_page(soup, extension=ext) - """Pretty print output as below""" + # Pretty print output as below print(''.join((b_colors.OKGREEN, 'Websites Found - ', b_colors.ENDC, str(len(websites))))) print('------------------------------------') From 85116d24190ccc0f743b2a09141a3d387253d8f2 Mon Sep 17 00:00:00 2001 From: Hossam Al-Dokkani Date: Sat, 21 Jul 2018 14:38:28 +0200 Subject: [PATCH 2/4] Fix bad-indentation --- modules/net_utils.py | 7 +++---- modules/pagereader.py | 13 +++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/net_utils.py b/modules/net_utils.py index bd2f1b16..ee600878 100644 --- a/modules/net_utils.py +++ b/modules/net_utils.py @@ -5,7 +5,6 @@ def check_connection(url): - print("Attempting to connect to {site}".format(site=url)) if get_url_status(url) != 0: return 1 @@ -28,9 +27,9 @@ def get_url_status(url, headers=False): """ try: if headers: - resp = requests.get(url, headers=headers) + resp = requests.get(url, headers=headers) else: - resp = requests.get(url) + resp = requests.get(url) resp.raise_for_status() return resp except (ConnectionError, HTTPError): @@ -41,7 +40,7 @@ def is_url(url): pattern = r"^https?:\/\/(www\.)?([a-z,A-Z,0-9]*)\.([a-z, A-Z]+)(.*)" regex = re.compile(pattern) if regex.match(url): - return 1 + return 1 return 0 diff --git a/modules/pagereader.py b/modules/pagereader.py index 6598be99..4952a06e 100644 --- a/modules/pagereader.py +++ b/modules/pagereader.py @@ -24,23 +24,23 @@ def read_first_page(site): continue if attempts_left == 2: - https_url = 'https://'+site + https_url = 'https://' + site print(next(connection_msg(https_url))) response = get_url_status(https_url, headers) if response != 0: - page = BeautifulSoup(response.text, 'html.parser') - return page, response + page = BeautifulSoup(response.text, 'html.parser') + return page, response else: attempts_left -= 1 continue if attempts_left == 1: - http_url = 'http://'+site + http_url = 'http://' + site print(next(connection_msg(http_url))) response = get_url_status(http_url, headers) if response != 0: - page = BeautifulSoup(response.text, 'html.parser') - return page, response + page = BeautifulSoup(response.text, 'html.parser') + return page, response else: attempts_left -= 1 continue @@ -50,6 +50,7 @@ def read_first_page(site): "connect to {site}.")).format(err=err, site=site) exit(msg) + def get_ip(): """Returns users tor ip address From ca6179eeeba1b5fca48af9e3651080fe45279839 Mon Sep 17 00:00:00 2001 From: Hossam Al-Dokkani Date: Sat, 21 Jul 2018 14:41:27 +0200 Subject: [PATCH 3/4] Fix redefined-builtin 'ConnectionError' and 'exit' --- modules/net_utils.py | 4 +--- modules/pagereader.py | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/net_utils.py b/modules/net_utils.py index ee600878..be71d46d 100644 --- a/modules/net_utils.py +++ b/modules/net_utils.py @@ -1,8 +1,6 @@ import re import requests -from requests.exceptions import ConnectionError, HTTPError - def check_connection(url): print("Attempting to connect to {site}".format(site=url)) @@ -32,7 +30,7 @@ def get_url_status(url, headers=False): resp = requests.get(url) resp.raise_for_status() return resp - except (ConnectionError, HTTPError): + except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError): return 0 diff --git a/modules/pagereader.py b/modules/pagereader.py index 4952a06e..bf49d4ce 100644 --- a/modules/pagereader.py +++ b/modules/pagereader.py @@ -1,7 +1,7 @@ +import sys from bs4 import BeautifulSoup from modules.net_utils import get_url_status from modules.bcolors import Bcolors -from sys import exit def connection_msg(site): @@ -48,7 +48,7 @@ def read_first_page(site): if not attempts_left: msg = ''.join(("There has been an {err} while attempting to ", "connect to {site}.")).format(err=err, site=site) - exit(msg) + sys.exit(msg) def get_ip(): From d99c11c178e6a57a345963436faf4f094954f574 Mon Sep 17 00:00:00 2001 From: Hossam Al-Dokkani Date: Sat, 21 Jul 2018 14:42:53 +0200 Subject: [PATCH 4/4] Remove unused-argument 'conn' --- torBot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torBot.py b/torBot.py index 655ac312..feebe36a 100644 --- a/torBot.py +++ b/torBot.py @@ -151,7 +151,7 @@ def get_args(): return parser.parse_args() -def main(conn=False): +def main(): args = get_args() connect(args.ip, args.port) link = args.url @@ -199,7 +199,7 @@ def main(conn=False): if __name__ == '__main__': try: - main(conn=True) + main() except KeyboardInterrupt: print("Interrupt received! Exiting cleanly...")