-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan.sh
executable file
·79 lines (71 loc) · 1.17 KB
/
scan.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
ip=$1
file=$2
l1=${ip%%.*}
ip=${ip#*.}
l2=${ip%%.*}
ip=${ip#*.}
l3=${ip%%.*}
ip=${ip#*.}
l4=${ip%%/*}
ip=${ip#*/}
subnet=$ip #mask
if echo "$l1" | grep [^0-9] >/dev/null;
then
echo "usage: ./scan.sh your_ip_subnet your_savingfile_name"
exit
fi
if echo "$l2" | grep [^0-9] >/dev/null;
then
echo "usage: ./scan.sh your_ip_subnet your_savingfile_name"
exit
fi
if echo "$l3" | grep [^0-9] >/dev/null;
then
echo "usage: ./scan.sh your_ip_subnet your_savingfile_name"
exit
fi
if echo "$l4" | grep [^0-9] >/dev/null;
then
echo "usage: ./scan.sh your_ip_subnet your_savingfile_name"
exit
fi
if echo "$subnet" | grep [^0-9] >/dev/null;
then
echo "usage: ./scan.sh your_ip_subnet your_savingfile_name"
exit
fi
#how many ip in this subnet
subnet=$((32-$ip))
num=$((2**($subnet)))
cnt=0
#scanning
while [[ $num -ge 0 ]]
do
ip="$l1.$l2.$l3.$l4"
echo "$ip"
nmap $ip | grep "Host is up"
if [ $? == 0 ];
then
echo $ip>>$file
fi
((num=$num-1))
if(($l4<255))
then
((l4=$l4+1))
else
((l4=0))
if(($l3<255))
then
((l3=$l3+1))
else
((l3=0))
if(($l2<255))
then
((l2=$l2+1))
else
((l2=0))
((l1=$l1+1))
fi
fi
fi
done