Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Arth
Arth

Posted on • Edited on

     

How to make requests over Tor?

To make requests over Tor using Python3, we are going to be utilizing a Python controller library forTor calledStem.

In order to do so, you need to install the stem package for your OS.

  • ForMacOS :pip3 install stem in a python3 venv ( recommended ).

  • ForUbuntu :sudo pip3 install stem in a python3 venv ( recommended ).

fromstemimportSignalfromstem.controlimportControllerwithController.from_port(port=9051)ascontroller:controller.authenticate(password='your password set for tor controller port in torrc')print("Success!")controller.signal(Signal.NEWNYM)print("New Tor connection processed")
Enter fullscreen modeExit fullscreen mode

However, you're not done yet. You might get this error :
get this error: error(61, 'Connection refused').
It's because Port 9051 is not open on your machine yet.
To fix this issue, you'll need to edit yourtorrc file and uncomment the corresponding lines.

ControlPort 9051## If you enable the controlport, be sure to enable one of these## authentication methods, to prevent attackers from accessing it.HashedControlPassword16:<your_password>
Enter fullscreen modeExit fullscreen mode

To generate your password, run :

tor --hash-password "<new_password>"
Enter fullscreen modeExit fullscreen mode

where<new_password> is the password that you want to set.

And you're done withMaking Requests over Tor.

Note : To run thetor commands, you need to havetor package installed. For MacOS, it can be easily installed usingbrew install tor.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I code cool stuff and produce music.
  • Joined

More fromArth

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp