tor_socks.rs 834 B

123456789101112131415161718192021222324
  1. #![deny(warnings)]
  2. // This is using the `tokio` runtime. You'll need the following dependency:
  3. //
  4. // `tokio = { version = "1", features = ["full"] }`
  5. #[tokio::main]
  6. async fn main() -> Result<(), reqwest::Error> {
  7. // Make sure you are running tor and this is your socks port
  8. let proxy = reqwest::Proxy::all("socks5h://127.0.0.1:9050").expect("tor proxy should be there");
  9. let client = reqwest::Client::builder()
  10. .proxy(proxy)
  11. .build()
  12. .expect("should be able to build reqwest client");
  13. let res = client.get("https://check.torproject.org").send().await?;
  14. println!("Status: {}", res.status());
  15. let text = res.text().await?;
  16. let is_tor = text.contains("Congratulations. This browser is configured to use Tor.");
  17. println!("Is Tor: {}", is_tor);
  18. assert!(is_tor);
  19. Ok(())
  20. }