forked from cybersecurity-team/TorBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.py
More file actions
58 lines (45 loc) · 1.3 KB
/
Copy pathproxy.py
File metadata and controls
58 lines (45 loc) · 1.3 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
"""
Module contains onion proxy related code
"""
import requests
proxies = {
'http': 'socks5h://localhost:9050',
'https': 'socks5h://localhost:9050'
}
session = requests.session()
session.proxies = proxies
def set_proxy(host, port):
"""
Sets host and port for tor proxies being used when performing
irequests to onion domains.
Args:
host (string): host name or IP Address
port (string): port number
"""
global proxies # Allows us to modify global variable directly
global session
proxies = {
'http': 'socks5h://' + host + ':' + port,
'https': 'socks5h://' + host + ':' + port
}
session.proxies = proxies
def proxy_get(url, headers=None):
"""
Peforms GET request using socks5 proxy
Args:
url (string): url to retreive
headers (dict): mapping of headers for requests
"""
if headers:
return session.get(url, headers=headers)
return session.get(url)
def proxy_head(url, timeout=10, headers=None):
"""
Peforms HEAD request using socks5 proxy
Args:
url (string): url to retreive
headers (dict): mapping of headers for requests
"""
if headers:
return session.head(url, timeout=timeout, headers=headers)
return session.head(url, timeout=timeout)