]> git.nbdom.net Git - nb.git/commitdiff
etc/profile.d/net.sh
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 27 Jun 2019 14:16:30 +0000 (15:16 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 27 Jun 2019 14:16:30 +0000 (15:16 +0100)
etc/profile.d/functions
etc/profile.d/net.sh

index 0e0052fa197a3107b6882a3143b0a3a444af5298..d8978fc20114bcf65516f0a59a8464ff79d13620 100755 (executable)
@@ -932,14 +932,3 @@ cron_d_install() {
        [ "$cron" != "$(crontab -l)" ] && echo "$cron" | crontab
 
 }
-
-ip_is_local() {
-       case "$1" in
-               10.*) return 0 ;;
-               172.16.*) return 0 ;;
-               172.2[0-9].*) return 0 ;;
-               172.31.*) return 0 ;;
-               192.168.*) return 0 ;;
-       esac
-       return 1
-}
index c0ab149c340a76f32b7ce63367286dce29d97587..cedcff9cfc8137506f32a655ea6e5fd7038a6493 100644 (file)
@@ -49,3 +49,26 @@ net_mask2cdr() {
         x=${1%%$3*}
         echo $(( $2 + (${#x}/4) ))
 }
+
+net_host_ip() {
+       host -s "$1" | awk '/has address/{print $4; exit}'
+}
+
+net_is_local() {
+       declare ip="${1:?Usage: net_is_local IP|HOST}"
+       case "$ip" in
+               [0-9][0-9]?[0-9]?.[0-9][0-9]?[0-9]?.[0-9][0-9]?[0-9]?.[0-9][0-9]?[0-9]?) [ 1 ];;
+               *) ip="$(net_host_ip "$ip")"
+       esac
+
+       [ -n "$ip" ] || return 2
+
+       case "$ip" in
+               10.*) return 0 ;;
+               172.16.*) return 0 ;;
+               172.2[0-9].*) return 0 ;;
+               172.31.*) return 0 ;;
+               192.168.*) return 0 ;;
+               *) return 1 ;;
+       esac
+}