27.03.2015 г.

Check alive ip with bash file

  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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash

#####################################

#This script    for                 #

#alive ip and show name                                #

#uses module arping and work                         #

#for this time only by Debian bases                   #

#####################################

#GLOBAL VARIABLE

LOGFILE=logping.log                #LogFile

ARPING="apt-get install arping"  #Install arping

HPING="apt-get install hping3"   #Install hping3

ETH=$1                                     #Device Name

IP=$(ifconfig $ETH | grep "inet addr" | cut -d":" -f2 | cut \

-d" " -f1 | cut -d"." -f1-3)    #Found Ip



#CREATE FUNCTION FOR READLINE

readlines()

{

while

read line; do

ping=`ping -c 1 -b $line` &&

echo -e "\n**********************************************************************"

echo "IP $line UP" `arp -i $ETH $line | grep ether | awk '{print "Name " $1 " With macaddr "$3}'`

echo -e "\n"

echo `hping3 -c 1 -i $ETH $line --scan 0-6000 -S |awk '{print $1}' 2>&1`



done < $LOGFILE

exit 1

}



if [ -s "$LOGFILE" ]

then

rm $LOGFILE

fi



#DONE WITH FUNCTION

#Check if corect start script

#t.e. enter device name eth0 for example



if [ $# -ne 1 ]; then

echo "Usage - ./ping_and_scan.sh (Enter device like eth0)"

exit

fi



#somtimes finction not work with

#start with user privileg

#next row check if script start

#with user access



if [ "$(id -u)" != "0" ]; then

   echo "This script must be run as root" 1>&2

   exit 1

fi



#For reason script work with

#arping, check if pacckages instaled

#if not it is installed with root access



if [ "$(dpkg -s arping | grep 'Status: install ok' | cut -d" " -f3)" != "ok" ];then

echo "packages arping is not installed - Packages Install "

echo `$ARPING` &&

exit 1

fi



if [ "$(dpkg -s hping3 | grep 'Status: install ok' | cut -d" " -f3)" != "ok" ];then

echo "packages hping3 is not isntalled - Packages Install "

echo `HPING` &&

exit 1

fi

#Variable for Device

#Check for ip address



ping_scanning(){

for addr in $(seq 1 255); do

arp_alive=`arping -c 1 $IP.$addr | grep "bytes from" |\

cut -d " " -f 5 | cut -d "(" -f 2 |\

cut -d ")" -f 1 1>&2 >> $LOGFILE &`

done

}



ping_scanning



echo "Arp is working Waiting "

while true; do

if ! pgrep arping > /dev/null; then

readlines

else

echo -n "."

fi

sleep .3

done

Няма коментари :

Публикуване на коментар