summaryrefslogtreecommitdiffstats
path: root/retiolum/bin/list-known-public-addresses
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2013-02-07 20:26:15 +0100
committermakefu <github@syntax-fehler.de>2013-02-07 20:26:15 +0100
commitdd6ad821a5a5bcb633b28a6d35e5e612d1f59094 (patch)
tree51a5281d1cbba3423eb5e9a86eb16d847fac5a6e /retiolum/bin/list-known-public-addresses
parent12fa3df06555c4ad6973602998a42446fbb52e70 (diff)
parent41fb505a5dc5c81965cc45dd00d14fe4150b8a42 (diff)
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'retiolum/bin/list-known-public-addresses')
-rwxr-xr-xretiolum/bin/list-known-public-addresses38
1 files changed, 38 insertions, 0 deletions
diff --git a/retiolum/bin/list-known-public-addresses b/retiolum/bin/list-known-public-addresses
new file mode 100755
index 00000000..21b1c389
--- /dev/null
+++ b/retiolum/bin/list-known-public-addresses
@@ -0,0 +1,38 @@
+#! /bin/sh
+#
+# printf '%s %s\n' hostname IP-address for each known public retiolum address
+#
+set -eu
+
+_list_hostname_address() {
+ cd /etc/tinc/retiolum/hosts
+ grep --with-filename '^Address' * |
+ sed -n '
+ s/: */ /
+ s/ *= */ /
+ s/ Address \([a-zA-Z0-9.:_]*\) \?.*/ \1/p'
+}
+_lookup_address() {
+ sed '
+ /:/!{/ [0-9.]*$/!{s/ / `dig +short /;s/$/` \&/}}
+ s/^/echo /
+ $s/$/\nwait/
+ ' | sh
+}
+_filter_public() {
+ 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
+ '
+}
+_filter_online() {
+ awk '
+ {print"nc -zw 2 "$2" 655 2>/dev/null && echo "$1" "$2" &"}
+ END {print"wait"}
+ ' | sh
+}
+
+_list_hostname_address | _lookup_address | _filter_public