cidr2ip

Small and simple program for converting a CIDR into a netmask
git clone https://noxz.tech/git/cidr2ip.git
cidr2ip

commit: c2b6c7fffe0902896cf7e5d3188a14909b80acf6
parent: 47ba61f0855b6104d7ab504ac0dbc92740e3cbab
author: z0noxz <chris@noxz.tech>
date:   Tue, 7 Aug 2018 10:20:39 +0200
read from stdin if applicable
Mcidr2ip12++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/cidr2ip b/cidr2ip
@@ -48,9 +48,17 @@ do_cidr2ip() {
     return 0
 }
 
+# read from stdin if applicable
+x="$1"
+if ! [ -t 0 ]; then
+    while read -r line; do
+        x="$line"
+    done
+fi
+
 # check if input is a CIDR, then process it
-if [ "$1" -eq "$1" ] 2> /dev/null && [ "$1" -le 32 ] && [ "$1" -gt 0 ]; then
-    do_cidr2ip "$1" && exit 0
+if [ "$x" -eq "$x" ] 2> /dev/null && [ "$x" -le 32 ] && [ "$x" -gt 0 ]; then
+    do_cidr2ip "$x" && exit 0
 fi
 
 # if all fails print usage