Skip to content

Instantly share code, notes, and snippets.

@jeroen
Last active January 30, 2024 20:45
Show Gist options
  • Save jeroen/5127c288f8914bdb20be to your computer and use it in GitHub Desktop.
Save jeroen/5127c288f8914bdb20be to your computer and use it in GitHub Desktop.
Using TOR in R
# Installing TOR on mac: brew install tor
# Run TOR on custom port: tor --SOCKSPort 9050
# Check the 'origin' field in the response to verify TOR is working.
library(httr)
GET("https://httpbin.org/get", use_proxy("socks5://localhost:9050"))
# Set proxy in curl
library(curl)
h <- new_handle(proxy = "socks5://localhost:9050")
req <- curl_fetch_memory("https://httpbin.org/get", handle = h)
cat(rawToChar(req$content))
# Set proxy globally (case sensitive!)
Sys.setenv(http_proxy = "socks5://localhost:9050")
Sys.setenv(HTTPS_PROXY = "socks5://localhost:9050")
# Even works in base R
readLines(base::url("https://httpbin.org/get", method = "libcurl"))
readLines(curl::curl("https://httpbin.org/get"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment