#!/bin/bash n=999 while [[ -n "$1" ]]; do f=$1 shift echo torrent file $f h=$(torrentcheck "$f"|sed -e "/info_hash/!d" -e "s/info_hash: //" -e "s/ /%/g") for t in $(torrentcheck "$f"|sed -e "s/^announce://" -e "/^ /!d" -e "s/^ //"); do case $t in http*) n=$[$n+1] echo testing $t $h curl -m 5 -o /tmp/x-$n.benc "$t?info_hash=$h&peer_id=00000000001111111111&key=deadbeef&left=0&uploaded=0&compact=1&downloaded=0&port=9999&event=started" 2>/dev/null if [[ -f /tmp/x-$n.benc ]]; then if grep -q ":\(complete\|downloaded\|interval\)" /tmp/x-$n.benc; then gsmkenc /tmp/x-$n.benc | perl -nle 'if (/^ "(.+?)" => (\d+)$/) { $x{$1}=$2; } elsif (/^ "peers" => (\w\w(?:,\w\w)*)/) { my @f=map{hex($_)}split /,/,$1; for (my $i=0 ; $i<@f ; $i+=6) { printf("%d.%d.%d.%d:%d\n", @f[$i..($i+3)], $f[$i+4]*256+$f[$i+5]); } } elsif (/^ "ip" => "(.*)"/) { $ip=$1; } elsif (/^ "port" => (\d+)/) { $port=$1; } elsif (/^ "peer id" => (.*)/) { $peer=$1; } elsif (/^ }/) { printf("%-25s %s\n", "$ip:$port", $peer); } END { printf("%s\n", join("\t", map { "$_=$x{$_}" } keys %x)); }' elif grep -q ":failure reason" /tmp/x-$n.benc; then gsmkenc /tmp/x-$n.benc else dump -a /tmp/x-$n.benc fi fi ;; udp*) echo udp not supported ;; esac done done