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
+}