summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xnetwork-topology-scanner28
1 files changed, 21 insertions, 7 deletions
diff --git a/network-topology-scanner b/network-topology-scanner
index 8db3315..a57c555 100755
--- a/network-topology-scanner
+++ b/network-topology-scanner
@@ -159,28 +159,42 @@ grep -vwF -- '-m conntrack' "${tmp_dir}/iptables" | \
sed '
s/^\(\S\+ \S\+\) \(\S\+\) \(\S\+\)$/f \1 \2 \3\nr \1 \3 \2/
' "${tmp_dir}/routes" \
- | sort -k2,5 -k1,1 \
+ | while read -r dir host ip from to; do
+ printf '%s %s %s %s %s %s\n' \
+ "${dir}" \
+ "${from}" \
+ "${to}" \
+ "${host}" \
+ "${ip}" \
+ "$(
+ printf '%s\n' "${from}" "${to}" | \
+ sort | \
+ sha512sum | \
+ awk '{print $1}'
+ )"
+ done \
+ | sort -k2,6 -k1,1 \
> "${tmp_dir}/routes.new"
uniq -uf1 "${tmp_dir}/routes.new" | tee /dev/stderr \
| grep '^f ' \
> "${tmp_dir}/routes"
-# todo : remove duplicates
-
uniq -df1 "${tmp_dir}/routes.new" \
| sed 's/^[fr] /b /' \
+ | sort -k4,6 -k1,3 \
+ | uniq -f3 \
>> "${tmp_dir}/routes"
rm "${tmp_dir}/routes.new"
sed '
- s/^f \(\S\+\) 4 \(\S\+\) \(\S\+\)$/"\1 \2" -> "\1 \3" [weight=0, color="#808080"];\n/
+ s/^f \(\S\+\) \(\S\+\) \(\S\+\) 4 \S\+$/"\3 \1" -> "\3 \2" [weight=0, color="#808080"];\n/
t
- s/^f \(\S\+\) 6 \(\S\+\) \(\S\+\)$/"\1 \2" -> "\1 \3" [weight=0, color="#000000"];\n/
+ s/^f \(\S\+\) \(\S\+\) \(\S\+\) 6 \S\+$/"\3 \1" -> "\3 \2" [weight=0, color="#000000"];\n/
t
- s/^b \(\S\+\) 4 \(\S\+\) \(\S\+\)$/"\1 \2" -> "\1 \3" [dir=both, weight=0, color="#808080"];\n/
+ s/^b \(\S\+\) \(\S\+\) \(\S\+\) 4 \S\+$/"\3 \1" -> "\3 \2" [dir=both, weight=0, color="#808080"];\n/
t
- s/^b \(\S\+\) 6 \(\S\+\) \(\S\+\)$/"\1 \2" -> "\1 \3" [dir=both, weight=0, color="#000000"];\n/
+ s/^b \(\S\+\) \(\S\+\) \(\S\+\) 6 \S\+$/"\3 \1" -> "\3 \2" [dir=both, weight=0, color="#000000"];\n/
t
d
' "${tmp_dir}/routes" \