Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve PEP8 Violations #12

Merged
merged 5 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 81 additions & 52 deletions modules/checker.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,96 @@
#!/usr/bin/python

import sys
import os
import re
import subprocess
import os
from urllib.request import urlopen
import sys
from json import load
from urllib.error import HTTPError
from urllib.parse import urlparse
from urllib.request import urlopen


def urlcanon(website, verbose):
if not website.startswith("http"):
if not website.startswith("www."):
website = "www." + website
if verbose:
print(("## URL fixed: " + website))
website = "http://" + website
if verbose:
print(("## URL fixed: " + website))
return website
def url_canon(website, verbose):
"""

:param website: String -
:param verbose: Boolean -
:return: String 'website' -
"""
if not website.startswith("http"):
if not website.startswith("www."):
website = "www." + website
if verbose:
print(("## URL fixed: " + website))
website = "http://" + website
if verbose:
print(("## URL fixed: " + website))
return website


def extract_domain(url, remove_http=True):
uri = urlparse(url)
if remove_http:
domain_name = f"{uri.netloc}"
else:
domain_name = f"{uri.netloc}://{uri.netloc}"
return domain_name
"""

:param url: String -
:param remove_http: Boolean -
:return: String 'domain_name' -
"""
uri = urlparse(url)
if remove_http:
domain_name = f"{uri.netloc}"
else:
domain_name = f"{uri.netloc}://{uri.netloc}"
return domain_name


# Create output path
def folder(website, verbose):
outpath = website
if not os.path.exists(outpath):
os.makedirs(outpath)
if verbose:
print(("## Folder created: " + outpath))
return outpath


# Check if TOR service is running
def checktor(verbose):
checkfortor = subprocess.check_output(['ps', '-e'])

def findwholeword(w):
return re.compile(r'\b({0})\b'.format(w), flags=re.IGNORECASE).search

if findwholeword('tor')(str(checkfortor)):
if verbose:
print("## TOR is ready!")
else:
print("## TOR is NOT running!")
print('## Enable tor with \'service tor start\' or add -w argument')
sys.exit(2)


# Check your IP from external website
def checkip():
try:
webipcheck = 'https://api.ipify.org/?format=json'
my_ip = load(urlopen(webipcheck))['ip']
print(('## Your IP: ' + my_ip))
except:
e = sys.exc_info()[0]
print(("Error: %s" % e + "\n## IP can't obtain \n## Is " + webipcheck + "up?"))
""" Creates an output path for the findings.

:param website: String - URL of website to crawl.
:param verbose: Boolean - Logging level.
:return: String 'out_path' - Path of the output folder.
"""
out_path = website
if not os.path.exists(out_path):
os.makedirs(out_path)
if verbose:
print(f"## Folder created: {out_path}")
return out_path


def check_tor(verbose):
"""Checks to see if TOR service is running on device.
Will exit if (-w) with argument is provided on application startup and TOR
service is not found to be running on the device.

:param verbose: Boolean -'verbose' logging argument.
:return: None
"""
check_for_tor = subprocess.check_output(['ps', '-e'])

def find_whole_word(word):
return re.compile(r'\b({0})\b'.format(word),
flags=re.IGNORECASE).search

if find_whole_word('tor')(str(check_for_tor)):
if verbose:
print("## TOR is ready!")
else:
print("## TOR is NOT running!")
print('## Enable tor with \'service tor start\' or add -w argument')
sys.exit(2)


def check_ip():
""" Checks users IP from external resource.
:return: None or HTTPError
"""
addr = 'https://api.ipify.org/?format=json'
try:
my_ip = load(urlopen(addr))['ip']
print(f'## Your IP: {my_ip}')
except HTTPError as err:
error = sys.exc_info()[0]
print(f"Error: {error} \n## IP cannot be obtained. \n## Is {addr} up? "
f"\n## HTTPError: {err}")
Loading