Skip to content

Instantly share code, notes, and snippets.

@leoluyi
Forked from jeroen/tor.R
Created December 12, 2016 05:55
Show Gist options
  • Save leoluyi/a438dc96d833d4555abfb0cbcdef4002 to your computer and use it in GitHub Desktop.
Save leoluyi/a438dc96d833d4555abfb0cbcdef4002 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