diff options
-rwxr-xr-x | backup.in | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -70,6 +70,19 @@ extract_ssh_ip_protocols() { fi } +connected_ip_versions() { + ip -o addr show scope global \ + | awk '{print $4}' \ + | sed ' + s@^\([0-9]\+\.\)\{3\}[0-9]\+\(/[0-9]\+\)\?$@4@ + t + s@^[0-9a-f][0-9a-f:]\+\(/[0-9]\+\)\?$@6@ + t + d + ' \ + | sort -u +} + if [ $# -eq 1 ]; then if [ "$1" == "--help" ]; then usage 0 @@ -101,8 +114,13 @@ QuellIP=$(echo "$3" | sed "s|^[a-zA-Z]*://||; s|^[a-zA-Z]*@||; s|:\?/.*$||") if [ "$#" -eq 3 ]; then Quelle="$3" ipVer=$( - extract_ssh_ip_protocols "${QuellIP}" \ - | sort -n \ + { + extract_ssh_ip_protocols "${QuellIP}" \ + | sort -n + extract_ssh_ip_protocols "${QuellIP}" \ + | grep -xF "$(connected_ip_versions)" \ + | sort -n + } \ | tail -n1 ) elif [ "$#" -eq 4 ]; then |