Skip to content

Instantly share code, notes, and snippets.

@superboum
Last active April 17, 2019 13:58
Show Gist options
  • Save superboum/df20d533e3fa60a413c6f330af20e5d2 to your computer and use it in GitHub Desktop.
Save superboum/df20d533e3fa60a413c6f330af20e5d2 to your computer and use it in GitHub Desktop.
Tor Streams To Circuits Mapping
#!/bin/bash
declare -A circuits
declare -A streams
# CircuitID SP CircStatus [SP Path]
# We capture CircuitID and Path
while read l; do
id=$(echo $l|grep -Po '^\d+')
circ=$(echo $l \
| grep -Po '[^ ]*$' \
| sed 's/,/ /g' \
| tr -d "\r")
#echo $id ++ ${circ[@]}
circuits[$id]=$circ
done <<< $( {
nc 127.0.0.1 9051 <<EOF
authenticate ""
getinfo circuit-status
quit
EOF
} | grep -Po '^\d+ BUILT [^ ]*' )
# StreamID SP StreamStatus SP CircuitID SP Target CRLF
# We capture CircuitID and Target
while read l; do
id=$(echo $l \
| grep -Po '^\d+ SUCCEEDED \d+' \
|grep -Po '\d+$')
url=$(echo $l \
|grep -Po '[^ ]*$' \
|tr -d "\r")
streams[$id]=$url
done <<< $( {
nc 127.0.0.1 9051 <<EOF
authenticate ""
getinfo stream-status
quit
EOF
} | grep -Po '^\d+ SUCCEEDED \d+ [^ ]*' )
# We show Target --> Path
for key in "${!streams[@]}"; do
echo "${streams[$key]} --> ${circuits[$key]}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment