Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sergi
Tor
Commits
11b2c6a4
Commit
11b2c6a4
authored
20 years ago
by
Roger Dingledine
Browse files
Options
Downloads
Patches
Plain Diff
add an in-progress python controller to test controlport
svn:r2701
parent
2cacb4e0
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
contrib/tor-control.py
+71
-0
71 additions, 0 deletions
contrib/tor-control.py
with
71 additions
and
0 deletions
contrib/tor-control.py
0 → 100755
+
71
−
0
View file @
11b2c6a4
#!/usr/bin/python2
#$Id$
import
socket
import
struct
import
sys
MSG_TYPE_SETCONF
=
0x0002
MSG_TYPE_GETCONF
=
0x0003
MSG_TYPE_AUTH
=
0x0007
def
parseHostAndPort
(
h
):
host
,
port
=
"
localhost
"
,
9050
if
"
:
"
in
h
:
i
=
h
.
index
(
"
:
"
)
host
=
h
[:
i
]
try
:
port
=
int
(
h
[
i
+
1
:])
except
ValueError
:
print
"
Bad hostname %r
"
%
h
sys
.
exit
(
1
)
elif
h
:
try
:
port
=
int
(
h
)
except
ValueError
:
host
=
h
return
host
,
port
def
receive_message
(
s
):
body
=
""
header
=
s
.
recv
(
4
)
length
,
type
=
struct
.
unpack
(
"
!HH
"
,
header
)
print
"
Got response length %d, type %d
"
%
(
length
,
type
)
if
length
:
body
=
s
.
recv
(
length
)
print
"
Got response length %d, type %d, body %s
"
%
(
length
,
type
,
body
)
return
length
,
type
,
body
def
pack_message
(
type
,
body
=
""
):
length
=
len
(
body
)
reqheader
=
struct
.
pack
(
"
!HH
"
,
length
,
type
)
return
"
%s%s
"
%
(
reqheader
,
body
)
def
authenticate
(
s
):
s
.
sendall
(
pack_message
(
MSG_TYPE_AUTH
))
length
,
type
,
body
=
receive_message
(
s
)
return
def
get_option
(
s
,
name
):
s
.
sendall
(
pack_message
(
MSG_TYPE_GETCONF
,
name
))
length
,
type
,
body
=
receive_message
(
s
)
return
def
do_main_loop
(
host
,
port
):
print
"
host is %s:%d
"
%
(
host
,
port
)
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
connect
((
host
,
port
))
authenticate
(
s
)
get_option
(
s
,
"
nickname
"
)
# get_option(s,"DirFetchPostPeriod\n")
return
if
__name__
==
'
__main__
'
:
if
len
(
sys
.
argv
)
!=
2
:
print
"
Syntax: tor-control.py torhost:torport
"
sys
.
exit
(
0
)
sh
,
sp
=
parseHostAndPort
(
sys
.
argv
[
1
])
do_main_loop
(
sh
,
sp
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment