52 lines
1.4 KiB
Bash
Executable File
52 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
# -*- mode: sh; tab-width: 8; encoding: utf-8-unix -*-
|
|
|
|
ROLE=toxcore
|
|
prog=$( basename $0 .bash )
|
|
NOW=`date "+%Y-%m-%d_%H"`
|
|
|
|
. /usr/local/bin/usr_local_tput.bash 2>/dev/null >/dev/null || exit 2
|
|
PREFIX=/var/local
|
|
BINDIR=$PREFIX/bin
|
|
[ -n "$USER" ] && USER=$( id -un )
|
|
|
|
DEBUG="" /usr/local/bin/proxy_ping_test.bash tor || exit 1
|
|
|
|
[ -n "$socks_proxy" ] || . /usr/local/bin/proxy_export.bash 2>/dev/null >/dev/null
|
|
[ -n "$socks_proxy" ] && sproxy=`echo $socks_proxy | sed -e 's@.*://@@'`
|
|
|
|
# https://nodes.tox.chat/json
|
|
ip=""
|
|
declare -a ports
|
|
|
|
[ $# -eq 0 ] && set -- ~/.config/tox/DHTnodes.json
|
|
|
|
cat "$@" | \
|
|
jq '.|with_entries(select(.key|match("nodes"))).nodes[]|select(.status_tcp)|select(.ipv4|match("."))|.ipv4,.tcp_ports' | while read line ; do
|
|
if [ -z "$ip" ] ; then
|
|
ip=`echo $line|sed -e 's/"//g'`
|
|
ports=()
|
|
continue
|
|
elif [ "$line" = '[' ] ; then
|
|
continue
|
|
elif [ "$line" = ']' ] ; then
|
|
grep -q "^wlan[1-9][ ]00000000" /proc/net/route || { ERROR no route ; exit 3 ; }
|
|
if [ "$ip" = '"NONE"' -o "$ip" = 'NONE' ] ; then
|
|
:
|
|
elif ping -c 1 $ip | grep '100% packet loss' ; then
|
|
WARN failed ping $ip
|
|
else
|
|
INFO $ip "${ports[*]}"
|
|
cmd="nmap -Pn -n -sT -p T:"`echo "${ports[*]}" |sed -e 's/ /,/g'`
|
|
DBUG $cmd $ip
|
|
$cmd $ip | grep /tcp
|
|
fi
|
|
ip=""
|
|
continue
|
|
else
|
|
port=`echo $line|sed -e 's/,//'`
|
|
ports+=("$port")
|
|
# echo '>>' $ip "${ports[*]}"
|
|
fi
|
|
done
|