aboutsummaryrefslogtreecommitdiff
path: root/bin/ping_subnet
diff options
context:
space:
mode:
authorJakob Stendahl <jakobste@uio.no>2020-08-27 09:16:27 +0200
committerJakob Stendahl <jakobste@uio.no>2020-08-27 09:16:27 +0200
commit67c181b213519205fe0e7bac4646349652835dbb (patch)
treee6986d8761e0f6fbfce7e92916679c1d284bf61f /bin/ping_subnet
parent80985a3f817074537bb5d997fc4923294a0c3993 (diff)
downloaddotfiles-67c181b213519205fe0e7bac4646349652835dbb.tar.gz
dotfiles-67c181b213519205fe0e7bac4646349652835dbb.zip
Update to p10k, and do some small updates
Diffstat (limited to 'bin/ping_subnet')
-rwxr-xr-xbin/ping_subnet33
1 files changed, 33 insertions, 0 deletions
diff --git a/bin/ping_subnet b/bin/ping_subnet
new file mode 100755
index 0000000..760d63b
--- /dev/null
+++ b/bin/ping_subnet
@@ -0,0 +1,33 @@
+#!/bin/bash
+first_ip=${1:-192.168.1.1}
+last_ip=${2:-192.168.1.254}
+
+alternate_dotted_quad_to_integer()
+{
+ IFS="." read a b c d <<< `echo $1`
+ echo "($a * 256 * 256 * 256) + ($b * 256 * 256) + ($c * 256) + $d" | bc
+}
+
+dotted_quad_to_integer()
+{
+ IFS="." read a b c d <<< `echo $1`
+ expr $(( (a<<24) + (b<<16) + (c<<8) + d))
+}
+
+integer_to_dotted_quad()
+{
+ local ip=$1
+ let a=$((ip>>24&255))
+ let b=$((ip>>16&255))
+ let c=$((ip>>8&255))
+ let d=$((ip&255))
+ echo "${a}.${b}.${c}.${d}"
+}
+
+start=$(dotted_quad_to_integer $first_ip)
+end=$(dotted_quad_to_integer $last_ip)
+for ip in `seq $start $end`
+do
+ ( ping -c1 -w1 ${ip} > /dev/null 2>&1 && integer_to_dotted_quad ${ip} ) &
+done
+wait