aboutsummaryrefslogtreecommitdiff
path: root/bin/ak-cjdns-scanner
blob: 875852d172b11c2f9a9d1fe2aaf7a916604e0fe2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
#
# Needs CJDNS tools in your PATH
#
# Ref: https://github.com/cjdelisle/cjdns
#
which dumpLinks > /dev/null 2>&1
if [ $? -ne 0 ]
then
    echo "You need to install cjdns and cjdns-tools"
    exit 1
fi

TEMPDIR="$(mktemp -d)"
AK_ZPEERSFILE="$HOME/.arching-kaos/peersFile"
cd $TEMPDIR
counter=0
printf '[' > walk.aknet
dumpLinks \
    | cut -d ' ' -f 2,4 \
    | sed 's/ /\n/g' \
    | sort \
    | uniq \
    | while read -r ip || [ -n "$ip" ]
do
    node_info="`curl \
        -A 'akd/0.1.0; https://github.com/arching-kaos' \
        --connect-timeout 3 \
        "http://[$(publictoip6 $ip)]:8610/v0/node_info" 2>/dev/null`"
    if [ "$?" == "0" ]
    then
        if [ "$counter" -ne "0" ]
        then
            printf ',' >> walk.aknet
        fi
        printf '{"cjdns":{"public_key":"%s","ip":"%s"},"node_info":%s}' \
            "$ip" "`publictoip6 $ip`" "$node_info" >> walk.aknet
        counter="`expr $counter + 1`"
    fi
done
printf ']' >> walk.aknet

mv walk.aknet $AK_ZPEERSFILE

rm -rf $TEMPDIR