-
Notifications
You must be signed in to change notification settings - Fork 3
/
netmasker.sh
executable file
·61 lines (49 loc) · 1.31 KB
/
netmasker.sh
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
function usage {
echo "Usage: $0 <network>"
exit 1
}
[ $# -ne 1 ] && usage
Ad=$(echo $1 | cut -d'.' -f1)
Bd=$(echo $1 | cut -d'.' -f2)
Cd=$(echo $1 | cut -d'.' -f3)
Dd=$(echo $1 | cut -d'.' -f4 | cut -d '/' -f1)
CIDR=$(echo $1 | cut -d'.' -f4 | cut -d '/' -f2)
netmask=""
for i in $(seq 1 $CIDR);do
netmask=$netmask"1"
[ $(($i%8)) -eq 0 ] && [ $i -ne 32 ] && netmask=$netmask"."
done
for i in $(seq $(($CIDR+1)) 32);do
netmask=$netmask"0"
[ $(($i%8)) -eq 0 ] && [ $i -ne 32 ] && netmask=$netmask"."
done
mskAb=$(echo $netmask | cut -d'.' -f1)
mskBb=$(echo $netmask | cut -d'.' -f2)
mskCb=$(echo $netmask | cut -d'.' -f3)
mskDb=$(echo $netmask | cut -d'.' -f4 | cut -d '/' -f1)
mskAd=$((2#$mskAb))
mskBd=$((2#$mskBb))
mskCd=$((2#$mskCb))
mskDd=$((2#$mskDb))
netAd=$(($Ad & $mskAd))
netBd=$(($Bd & $mskBd))
netCd=$(($Cd & $mskCd))
netDd=$(($Dd & $mskDd))
imskAd=$(($mskAd ^ 255))
imskBd=$(($mskBd ^ 255))
imskCd=$(($mskCd ^ 255))
imskDd=$(($mskDd ^ 255))
brdAd=$((netAd | imskAd))
brdBd=$((netBd | imskBd))
brdCd=$((netCd | imskCd))
brdDd=$((netDd | imskDd))
for i in $(seq $netAd $brdAd);do
for j in $(seq $netBd $brdBd);do
for k in $(seq $netCd $brdCd);do
for l in $(seq $netDd $brdDd);do
echo $i.$j.$k.$l
done
done
done
done