Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
toRussiaWithTor
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Juan Cruz-Benito
toRussiaWithTor
Commits
948f4142
Commit
948f4142
authored
Feb 01, 2017
by
Juan Cruz-Benito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating code and requirements
parent
a939b0ad
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
0 deletions
+65
-0
tor_sample.py
code/tor_sample.py
+63
-0
requirements.txt
requirements.txt
+2
-0
No files found.
code/tor_sample.py
0 → 100644
View file @
948f4142
#Using "To Russia with love" tutorial to connect & stablish a TOR circuit
# https://stem.torproject.org/tutorials/to_russia_with_love.html
#
# This code is different from the provided by the tutorial due special configuration
# needed for tor_process in MacOS
import
socks
# SocksiPy module
import
socket
import
urllib
import
io
import
stem.process
from
stem
import
Signal
from
stem.control
import
Controller
from
stem.util
import
term
SOCKS_PORT
=
7000
# Set socks proxy and wrap the urllib module
socks
.
setdefaultproxy
(
socks
.
PROXY_TYPE_SOCKS5
,
'127.0.0.1'
,
SOCKS_PORT
)
socket
.
socket
=
socks
.
socksocket
# Perform DNS resolution through the socket
def
getaddrinfo
(
*
args
):
return
[(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
,
6
,
''
,
(
args
[
0
],
args
[
1
]))]
socket
.
getaddrinfo
=
getaddrinfo
def
query
(
url
):
"""
Uses urllib to fetch a site using SocksiPy for Tor over the SOCKS_PORT.
"""
try
:
return
urllib
.
urlopen
(
url
)
.
read
()
except
:
return
"Unable to reach
%
s"
%
url
def
print_bootstrap_lines
(
line
):
if
"Bootstrapped "
in
line
:
print
(
term
.
format
(
line
,
term
.
Color
.
BLUE
))
print
(
term
.
format
(
"Starting Tor:
\n
"
,
term
.
Attr
.
BOLD
))
tor_process
=
stem
.
process
.
launch_tor_with_config
(
tor_cmd
=
'/Applications/TorBrowser.app/Contents/MacOS/Tor/tor.real'
,
config
=
{
'SocksPort'
:
str
(
SOCKS_PORT
),
'ExitNodes'
:
'{ru}'
,
'GeoIPFile'
:
r'/Applications/TorBrowser.app/Contents/Resources/TorBrowser/Tor/geoip'
,
'GeoIPv6File'
:
r'/Applications/TorBrowser.app/Contents/Resources/TorBrowser/Tor/geoip6'
},
init_msg_handler
=
print_bootstrap_lines
,
)
print
(
term
.
format
(
"
\n
Checking our endpoint:
\n
"
,
term
.
Attr
.
BOLD
))
print
(
term
.
format
(
query
(
"https://www.atagar.com/echo.php"
),
term
.
Color
.
BLUE
))
tor_process
.
kill
()
# stops tor
requirements.txt
0 → 100644
View file @
948f4142
PySocks
==1.6.6
stem
==1.5.4
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment