Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rb:findipdevices [17/01/2013 15:43]
andrew
rb:findipdevices [10/10/2013 14:21] (current)
Line 7: Line 7:
   #intended to loop through range of addresses and ping them to discover active devices.   #intended to loop through range of addresses and ping them to discover active devices.
   #This fails of course if a device is set to ignore icmp.   #This fails of course if a device is set to ignore icmp.
 +  ​
 +  #turn on debugging, -x starts, +x stops
 +  set +x
 +  ​
   ​   ​
   #​BASEIP=10.106.18   #​BASEIP=10.106.18
-  BASEIP=10.28.161+  BASEIP=192.168.1
   ​   ​
   ​   ​
-  DNSSERVER=10.170.2.4+  DNSSERVER=192.168.1.1
   ​   ​
-  for IPADDRESS in {20..30}+  for IPADDRESS in {1..50}
   do   do
           #echo "​Testing >​${BASEIP}.${IPADDRESS}<​."​           #echo "​Testing >​${BASEIP}.${IPADDRESS}<​."​
   ​   ​
-          #Prime Ping with a dummy ping which we ignore +          #Prime Ping with a dummy ping which we ignore, timeout 2 seconds 
-          ping -c1 ${BASEIP}.${IPADDRESS} ​ 2>&1 > /dev/null+          ping -t 2 -c1 ${BASEIP}.${IPADDRESS} ​ 2>&1 > /dev/null
   ​   ​
-          #Now record the result, RC0=reply, RC1=no reply  +          #Now record the result, RC0=reply, RC1=no reply, RC2=sent but no reply (mac)  
-          ping -c1 ${BASEIP}.${IPADDRESS} ​ 2>&1 > /dev/null+          ping -t 2 -c1 ${BASEIP}.${IPADDRESS} ​ 2>&1 > /dev/null
           PINGRESULT=$?​           PINGRESULT=$?​
   ​   ​
Line 28: Line 32:
                   echo " "                   echo " "
                   echo "​Device found on ${BASEIP}.${IPADDRESS}"​                   echo "​Device found on ${BASEIP}.${IPADDRESS}"​
-                  DNSNAME=`dig @${DNSSERVER} -x ${BASEIP}.${IPADDRESS} | grep -A1  ";; ANSWER"​ | grep -v ";;"​` +                  DNSNAME=`dig @${DNSSERVER} -x ${BASEIP}.${IPADDRESS} | grep -A1  ";; ANSWER"​ | grep -v ";;"​` ​2>&1 > /dev/null 
-                  echo "DNS lookup gives >${DNSNAME}<​."​+  LOOKUPRET=$?
   ​   ​
 +  if [ "​${LOOKUPRET}"​ -eq 0 ]; then
 +  echo "DNS lookup gives >​${DNSNAME}<​."​
 +  else ​
 +  echo "No dns lookup found"
 +  fi
   ​   ​
           elif [ "​${PINGRESULT}"​ -eq 1 ]; then           elif [ "​${PINGRESULT}"​ -eq 1 ]; then
 +                  DUMMY=1
 +                  echo -n "​."​
 +          elif [ "​${PINGRESULT}"​ -eq 2 ]; then
 +  #Mac rc=2 means ping sent ok, but no reply
                   DUMMY=1                   DUMMY=1
                   echo -n "​."​                   echo -n "​."​
Line 46: Line 59:
   ​   ​
   exit 0   exit 0
- 
  
  

rb/findipdevices.txt · Last modified: 10/10/2013 14:21 (external edit)