I've a program that with an algorithm generate link in .onion. Some link runs, some no. For check if every link runs, I would ask this: Is it possible to ping a link .onion? If yes, how to Can I do it?
4 Answers
ping, assuming you're talking about the *nix command, is ICMP. Tor is exclusively TCP in the requests carried across the network. You cannot "ping" an onion.
If you want to know if an onion is online, you can try to connect to it. A more heuristic method might be to fetch the onion's descriptor and see when it was published but that doesn't mean it's online, or ever was, just that it published a descriptor to the HSDir at some point during that hour.
- 11,047
- 2
- 17
- 39
As @canonizingironize said - there's no ICMP in Tor. Actually, there's nothing except TCP in Tor. But there's a way to "ping" an onion:
- Any service has a TTFB(Time To First Byte) timing, and when you're connecting to it - on your side time to first byte is TTFB++, i.e. "ping delay", roughly speaking
- So - assuming that server-side TTFB is semi-equal(actually it is - in case of a proper server, jitter is +/- 1-2 miliseconds), you can use it in math model to make a system of equations and you can estimate server-side TTFB
This method will give you a very rough "packet travel time" estimation rounded to tens of miliseconds, but if you need it anyway - it's better than nothing.
- 6,385
- 3
- 15
- 36
I found a tool which uses http pings to check if the website is online, tells you how many ms of response and status code: https://github.com/Isloka/tor-pinger/
- 11
- 1
Yes, prerequisites for this function:
sudo apt install tor -y
sudo apt install torsocks -y
sudo apt install httping -y
Here is a function that does it:
# Returns "FOUND" if an onion was available on the first try.
# TODO: allow for retries in parsing ping output.
onion_is_available() {
local onion="$1"
local port="$2"
local address
if [ "$port" == "" ]; then
address="$onion"
else
address="$onion:$port"
fi
local ping_output
ping_output=$(torsocks httping --count 1 "$address")
if [[ "$ping_output" == "100,00% failed" ]]; then
echo "NOTFOUND"
elif [[ "$ping_output" == "1 connects, 1 ok, 0,00% failed, time" ]]; then
echo "FOUND"
else
echo "Error, did not find status."
exit 5
fi
}
You can call it with:
local found_it_or_not
found_it_or_not=$(onion_is_available "protonmailrmez3lotccipshtkleegetolb73fuirgj7r4o4vfu7ozyd.onion")
echo "found_it_or_not=$found_it_or_not"
or (with specific port):
local found_it_or_not
found_it_or_not=$(onion_is_available "protonmailrmez3lotccipshtkleegetolb73fuirgj7r4o4vfu7ozyd.onion" 80)
echo "found_it_or_not=$found_it_or_not"
It does just one try (count 1), and I did not include retries, because I did not parse the n ok, part in the httping output with variable n in range of 1 to x for (count x). So feel free to improve this answer by including retries.
if found_it_or_not is FOUND then the onion domain was accessible (on that port) otherwise, it was not.
- 153
- 5