How To Anonymize Your cURL Requests Using Tor

How To Anonymize Your cURL Requests Using Tor

Note: This post assumes that you already have Tor installed and configured on your server. If not, visit the Tor Project Homepage for instructions on how to set it up.

I love writing web crawlers and data aggregators in PHP. They say knowledge is power, and I find it exciting to write applications that allow you to gather up as much knowledge as possible. Sometimes, though, you want to gather your data without revealing your identity to your target. This can be for both good and bad reasons, but let’s assume it is for a good reason that you need to keep hidden. The Tor Project is a great way to accomplish this task. Tor allows you to anonymously browse the web, and you can configure the applications on your computer to run through the Tor network. The script below outlines the process it takes to randomly refresh your IP address on Tor, and then run a cURL request through your local Tor proxy, providing a unique identity and anonymity every time you run the script.

For this particular example, I am sending a request to to demonstrate the changing IP address. If you have a greater understanding of cURL, there are many more steps that can be taken to mask your identity as well, but I won’t go into that here.

  • Very helpful, thank you so much

  • Yeah, thanks! Really helped! :)

  • Mr Roboto
  • Kevin Steger

    Is there a way to determine from Tor what exit node was used? e.g. if I have exitnodes {US,CA} is there a way to tell which country exit it went through?

  • Mark

    IP is not rotating. And what is $auth = ‘PASSWORD’; for?

    • Hi Mark,

      $auth = ‘PASSWORD’; is the password that you used when configuring your Tor service (replacing PASSWORD with your own password of course). If authentication isn’t properly setup, then you won’t be able to rotate your IP, which might explain your issue.

  • bjas lolor

    I installed tor browser on a VM but I do not remember it asking for a pw. At what point in the process was that supposed to occur. Note: I am on windows not linux. I would like to be able to use a script like this to be able to get different IP each time the script is run.

    • Hi @bjaslolor:disqus, if I remember correctly setting up the password is a manual process. To do that, modify your torrc file and add the HashedControlPassword directive using the result from the tor –hash-password command. Hopefully that helps, but you can find more detailed information here:

  • Adam Interact

    Somehow it was rotating for 4-5 times and stopped. Any clue?