How to correctly programatically check if Tor socks proxy is working or not?
I have been thinking lately how to check correctly whether Tor is actually working or not in an application that sends HTTP requests over Tor. I'm aware that this question is somewhat fuzzy because one needs to define "Tor is working" (and when "It is not working") and in networking world this is not an easy question.
Anyway, I've come up with the following list of thoughts what one can do:
- Check that Tor OS process is running [Quick heuristic]
- Remember the last time an HTTP request went through Tor successfully [May help when an app sends HTTP requests somewhat periodically]
- Check whether Tor is working using Tor control (source)
- Send
GETINFO status/circuit-established
request to find out whether a circuit was established or not.- I'm not sure about semantics here. Is it "Is a circuit established now?" or "Was ever a circuit established?"
- Send
GETINFO traffic/read
andGETINFO traffic/written
requests to find out whether some data got through.- note: Maybe a user can write some data but nothing comes back or there is no traffic at all.
- Send
- Send HTTP request with URL
check.torproject.org
to verify Tor is really running- May have false negatives because:
- Not all exits exit from their advertised IP addresses, the Tor Project probes each exit periodically but some of them change the IP they exit from semi-frequently. This means that the check.tpo site will think it's not a Tor IP address in a small number of cases and report that you aren't using Tor when infact you are. (source)
- This sounds like a bad idea to me because it strains Tor network unnecessarily.
- May have false negatives because:
Note: Is there a way to ask Tor if whether it runs on a OS with correctly set system clock? This is a known issue and it sounds like a common source of troubles.
Does this approach sounds about right? Would you add something?
Resources:
- https://tor.stackexchange.com/questions/19858/how-to-check-if-tor-socks-proxy-is-working-programatically-python
- https://tor.stackexchange.com/questions/12678/how-to-check-if-tor-is-working-and-debug-the-problem-on-cli
- https://security.stackexchange.com/questions/12395/how-does-check-torproject-org-know-if-youre-using-tor