forked from cybersecurity-team/TorBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpagereader.py
More file actions
80 lines (63 loc) · 2.13 KB
/
Copy pathpagereader.py
File metadata and controls
80 lines (63 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
This module is used for reading HTML pages using either bs4.BeautifulSoup objects or url strings
"""
from bs4 import BeautifulSoup
from .utils import get_url_status
from .color import color
def read(link, *, response=False, show_msg=False, headers=None, schemes=None):
"""
Attempts to retrieve HTML from link
Args:
headers (dict)
schemes (list)
Returns:
resp.text (str): html from page
"""
headers = {'User-Agent': 'XXXX-XXXXX-XXXX'} if not headers else headers
# Attempts to connect directly to site if no scheme is passed
if not schemes:
if show_msg:
print(f"Attempting to connect to {link}")
resp = get_url_status(link, headers)
if resp != 0:
if response:
return resp.text, resp
return resp.text
schemes = ['https://', 'http://'] if not schemes else schemes
for scheme in schemes:
temp_url = scheme + link
if show_msg:
print(f"Attempting to connect to {link}")
resp = get_url_status(temp_url, headers)
if resp != 0:
if response:
return resp.text, resp
return resp.text
raise ConnectionError
def display(link):
"""
Prints the status of a link
"""
resp = get_url_status(link)
if resp != 0:
try:
title = BeautifulSoup(resp.text, 'html.parser').title.string
link_status = color(link, 'green')
except AttributeError:
title = "Not Found"
link_status = color(link, 'red')
else:
title = "Not Found"
link_status = color(link, 'red')
print("%-80s %-30s" % (link_status, title))
def display_ip():
"""Returns users tor ip address
https://check.torproject.org/ tells you if you are using tor and it
displays your IP address which we scape and return
"""
page = read('https://check.torproject.org/')
page = BeautifulSoup(page, 'html.parser')
ip_cont = page.find('strong')
ip_addr = ip_cont.renderContents()
ip_string = color(ip_addr.decode("utf-8"), 'yellow')
print(f'Tor IP Address: {ip_string}')