cybrkyd

Using CURL with TOR

 Tue, 14 May 2024 09:33 UTC
Using CURL with TOR
Image: CC BY 4.0 by cybrkyd

There is the odd occasion where I want to download files incognito, that is, where my IP address is masked. To use Tor as a proxy for HTTP requests with curl or wget, install Tor.

$ sudo apt install tor

Check that Tor is running:

$ systemctl status tor
● tor.service - Anonymizing overlay network for TCP (multi-instance-master)
     Loaded: loaded (/lib/systemd/system/tor.service; enabled; vendor preset: enabled)
     Active: active (exited) since Mon 2024-05-13 12:30:39 BST; 20h ago
    Process: 870 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 870 (code=exited, status=0/SUCCESS)
        CPU: 765us

May 13 12:30:39 my-pc systemd[1]: Starting Anonymizing overlay network for TCP (multi-instance-master)...
May 13 12:30:39 my-pc systemd[1]: Finished Anonymizing overlay network for TCP (multi-instance-master).

Tor listens on TCP port 9050 by default. To download a single file, this command can be used:

$ curl --socks5-hostname localhost:9050 "https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Cat_August_2010-4.jpg/1920px-Cat_August_2010-4.jpg" -o "/home/cybrkyd/Pictures/Cat_August_2010-4.jpg"

To download multiple files, a shell script can be used to read URLs from a plain text file.

#!/bin/bash

# Read each URL from pix.txt and download using curl over TOR
while IFS= read -r url; do
  filename=$(basename "$url")  # Extract the filename from the URL
  curl --socks5-hostname localhost:9050 -o "/home/cybrkyd/Pictures/$filename" "$url"
done < pix.txt

Tor is slow. If you have hundreds of files to download, set the script to run and go do something else. Make a cup of tea or coffee!

»
Tagged in:

Visitors: Loading...