summaryrefslogtreecommitdiffstats
path: root/retiolum/bin/list-known-public-addresses
blob: d157cea41dd8a82e6398711e186d1d56e81ac700 (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
#! /bin/sh
#
# printf '%s %s\n' hostname IP-address for each known public retiolum address
#
set -eu

cd /etc/tinc/retiolum/hosts

grep --with-filename '^Address' * |
sed '
  # filter "%s %s %s\n" hostname var val
  s/: */ /
  s/ *= */ /
  # filter "%s %s\n" hostname address
  s/ Address \([a-zA-Z0-9.:_]*\) \?.*/ \1/
  T
  # prepare hostname lookup
  /:/!{/ [0-9.]*$/!{s/ / `dig +short /;s/$/` \&/}}
  s/^/echo /
  $s/$/\nwait/
  # perform hostname lookup
' | sh | sed '
  # drop private IPv4 addresses
  / 10\./d
  / 172\.\(1[6-9]\|2[0-9]\|3[01]\)\./d
  / 192\.168\./d
  # TODO drop private IPv6 addresses
'