Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
609 views
in Technique[技术] by (71.8m points)

cmd - Request new Tor identity from Windows command line

I'm trying to use a simple Windows Command Line command to change TOR identities. I see plenty of examples for Linux, but not sure how to implement the same thing on Windows.

Anyone have any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

UPDATE: Using stream isolation as shown in this answer may be a way to get around needing to use the control port to request a new identity. Using a username & password on the SOCKS connection isolates those requests to a specific circuit and changing the credentials will automatically change the circuit which results in getting a new IP.

To create a new circuit (switch IP addresses) on Windows without stopping and starting Tor, you need to open a connection to Tor's control port to issue a NEWNYM signal.

Here is a batch file that will achieve this. You also need to download netcat for Windows and put nc.exe in the same folder as this batch file.

I downloaded the Tor Browser Bundle for Windows, so you will need to put this batch file in the root folder of the browser bundle.

@echo off

REM Read control auth cookie into variable
set /p auth_cookie=<BrowserTorBrowserDataTorcontrol_auth_cookie

REM Create file with control commands
echo AUTHENTICATE "%auth_cookie%"> commands.txt
echo SIGNAL NEWNYM>> commands.txt
echo QUIT>> commands.txt

REM Connect to control port and issue commands
nc localhost 9151 < commands.txt

REM Delete commands file
del /Q commands.txt

I tested this on Windows and after running the batch file, my circuit changed and I had a new IP each time.

When you run it, you should see the following output:

C:UsersuserDesktopTor Browser>control.bat
250 OK   <-- in response to AUTHENTICATE
250 OK   <-- in response to SIGNAL NEWNYM
250 closing connection

There is no simple one-liner, you have to connect to the control port and issue this signal. This is what the browser does when you press the new identity button.

Here is the directory structure relative to the Tor Browser Bundle, nc, and the batch file to create a new circuit.

file structure


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...