forked from r0oth3x49/Tor
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcreate_intermediate_tor_proxy.py
49 lines (42 loc) · 1.31 KB
/
create_intermediate_tor_proxy.py
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
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 23 22:15:33 2021
@author: Yicong
"""
import io
import os
import stem.process
import re
import urllib.request
import requests
import json
from datetime import datetime
SOCKS_PORT = 9050
CONTROL_PORT = 9051
TOR_PATH = os.path.normpath(os.getcwd()+"\\tor\\tor.exe")
GEOIPFILE_PATH = os.path.normpath(os.getcwd()+"\\data\\tor\\geoip")
try:
urllib.request.urlretrieve('https://raw.githubusercontent.com/torproject/tor/main/src/config/geoip', GEOIPFILE_PATH)
except:
print ('[INFO] Unable to update geoip file. Using local copy.')
tor_process = stem.process.launch_tor_with_config(
config = {
'SocksPort' : str(SOCKS_PORT),
'ControlPort' : str(CONTROL_PORT),
'EntryNodes' : '{FR}',
'ExitNodes' : '{JP}',
'StrictNodes' : '1',
'CookieAuthentication' : '1',
'MaxCircuitDirtiness' : '60',
'GeoIPFile' : GEOIPFILE_PATH,
},
init_msg_handler = lambda line: print(line) if re.search('Bootstrapped', line) else False,
tor_cmd = TOR_PATH
)
PROXIES = {
'http': 'socks5://127.0.0.1:9050',
'https': 'socks5://127.0.0.1:9050'
}
response = requests.get("http://ip-api.com/json/", proxies=PROXIES)
result = json.loads(response.content)
print('TOR IP [%s]: %s %s'%(datetime.now().strftime("%d-%m-%Y %H:%M:%S"), result["query"], result["country"]))