Our experts are always on hand to help answer your questions, get you started, and grow your presence online. You can email us any time
How to use CURL with TOR as a proxy?
CURL is a utility that facilitates data transfer to or from a server through the use of URLs.
Tor, an acronym for The Onion Router, is an open-source software that is free to use and promotes anonymous interactions online. It routes internet traffic through a global volunteer-driven overlay network comprising over seven thousand relays. The use of Tor increases the challenge of tracing a user's online activities.
This guide outlines two common methods to utilize CURL with TOR as a proxy.
The initial method involves installing the Tor Browser, which can be downloaded from the official Tor website. The website provides instructions to download a version compatible with your operating system. After the download is complete, the next step is to install the browser on your device. The installation process is straightforward and similar to that of any other software or application.
Download Tor Browser for Windows
Download Tor Browser for macOS
Download Tor Browser for Android
The first time you launch the Tor Browser, connection to the Tor network must be established. This can be achieved by clicking the "Connect" button found on the browser's interface. This step is required only during the initial use of the Tor Browser. It is meant to ensure a secure and private connection to the Tor network.
After the connection is established, you can use the Tor Browser as a proxy to connect to a URL. The Tor Browser opens the SOCKS proxy on 127.0.0.1:9150. CURL can utilize this mechanism as a proxy to connect .com or .onion services.
Below commands are example on how to use CURL with tor as a proxy.
curl --socks5-hostname 127.0.0.1:9150 https://api.ipify.org curl --socks5-hostname 127.0.0.1:9150 http://2gzyxa5ihm7nsggfxnu52rck2vv4rvmdlkiu3zzui5du4xyclen53wid.onion
The first command response the IP address of your Tor instance exit node, instead of your IP address. This is the result of CURL using Tor as a proxy.
The second command response the Tor project offical site.
The --socks5-hostname flag is used, instead of --socks5, because it will try to resolve the domain name using the Tor instance, instead of local system domain name resolver.
The second method introduced is by utilizing Docker. Docker is a software platform designed to facilitate building, testing, and deploying applications with speed. It organizes software into uniform units known as containers, which incorporate all the necessary components for the software's operation, such as libraries, system tools, code, and runtime. Docker enables swift deployment and scaling of applications in any environment, ensuring the smooth running of your code.
To utilize Docker to run Tor instance, execute the below command:
$ docker run --rm -p 9050:9050 osminogin/tor-simple Mar 27 01:36:09.530 [notice] Tor 0.4.8.10 running on Linux with Libevent 2.1.12-stable, OpenSSL 3.1.2, Zlib 1.3, Liblzma 5.4.5, Libzstd 1.5.5 and Unknown N/A as libc. Mar 27 01:36:09.530 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://support.torproject.org/faq/staying-anonymous/ Mar 27 01:36:09.530 [notice] Read configuration file "/etc/tor/torrc". Mar 27 01:36:09.533 [warn] You specified a public address '0.0.0.0:9050' for SocksPort. Other people on the Internet might find your computer and use it as an open proxy. Please don't allow this unless you have a good reason. Mar 27 01:36:09.533 [notice] Opening Socks listener on 0.0.0.0:9050 Mar 27 01:36:09.534 [notice] Opened Socks listener connection (ready) on 0.0.0.0:9050 Mar 27 01:36:09.534 [warn] Fixing permissions on directory /var/lib/tor
The docker run command runs a command in a new container, pulling the image if needed and starting the container. In this example, it pulls a public Tor image from the Docker Hub registry. Use --rm flag to specify that the container should be removed when it exits. Use -p flag to publish a container port 9050 to the host.
Then, you can follow the same step to execute CURL with tor as a proxy
curl --socks5-hostname 127.0.0.1:9050 https://api.ipify.org curl --socks5-hostname 127.0.0.1:9050 http://2gzyxa5ihm7nsggfxnu52rck2vv4rvmdlkiu3zzui5du4xyclen53wid.onion
Note that when you run Tor instance using Docker, the SOCKS port is 9050, which differs than the SOCKS port used in Tor Browser. This is to ensure that there is no conflict when your system runs Tor instance and Tor Browser at the same time.
This guide demonstrates two common ways of how to use CURL with TOR as a proxy.
Our experts are always on hand to help answer your questions, get you started, and grow your presence online. You can email us any time