-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmynetwork
More file actions
executable file
·61 lines (56 loc) · 1.15 KB
/
mynetwork
File metadata and controls
executable file
·61 lines (56 loc) · 1.15 KB
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
NETWORK=$(ifconfig | grep inet | grep netmask | grep -v 127.0.0 | gawk '{print $2" "$4}')
IP=$(echo $NETWORK | gawk '{print $1}')
MASK=$(echo $NETWORK | gawk '{print $2}')
if [ $MASK == "255.255.255.0" ]
then
NET=3
SUB=1
DECMASK=24
HOSTS=".0"
elif [ $MASK == "255.255.0.0" ]
then
NET=2
SUB=2
DECMASK=16
HOSTS=".0.0"
else
NET=1
SUB=3
DECMASK=8
HOSTS=".0.0.0"
fi
echo "My details: IP=$IP Mask=$MASK Net=$NET Sub=$SUB"
NETPART=$(echo $IP | cut -d"." -f-$NET)
SEARCH=${NETPART}${HOSTS}
echo "Searching $SEARCH"
OLDIFS=$IFS
IFS="
"
for LINE in $(nmap -sP $SEARCH/$DECMASK | grep -v latency | sed 's/Nmap scan report for / /')
do
echo $LINE
FLAG=$(echo $LINE | grep $NETPART)
if [ -z "$FLAG" ]
then
continue
else
FOUND="$FOUND $LINE"
fi
done
exit
#######################################
IFS=$OLDIFS
for LINE in $FOUND
do
FLAG=$(echo $LINE | grep $NETPART)
if [ -z "$FLAG" ]
then
continue
else
HOST=$(echo "$LINE" | sed 's/[\(\)]//g')
echo "___________________________________"
echo "Scanning $HOST"
sudo nmap -O $HOST
fi
done