blob: 760d63b85ac085a1198eea745e116599c77179a5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
|