home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / ifupdown / examples / ping-places.sh < prev   
Encoding:
Linux/UNIX/POSIX Shell Script  |  2005-05-12  |  605 b   |  31 lines

  1. #!/bin/sh
  2.  
  3. if [ `id -u` -ne 0 ] || [ "$1" = "" ]; then exit 1; fi
  4.  
  5. if [ -x /usr/bin/fping ]; then
  6.     PING="/usr/bin/fping"
  7. else
  8.     PING="/bin/ping -c 2"
  9. fi
  10.  
  11. iface="$1"
  12. which=""
  13.  
  14. while read addr pingme scheme; do
  15.     if [ "$which" ]; then continue; fi
  16.  
  17.     #echo "  Trying $addr & $pingme ($scheme)" >&2
  18.  
  19.     ip addr add $addr dev $iface  >/dev/null 2>&1
  20.     ip link set $iface up         >/dev/null 2>&1
  21.  
  22.     if $PING $pingme >/dev/null 2>&1; then
  23.         which="$scheme"    
  24.     fi
  25.     ip link set $iface down       >/dev/null 2>&1
  26.     ip addr del $addr dev $iface  >/dev/null 2>&1
  27. done
  28.  
  29. if [ "$which" ]; then echo $which; exit 0; fi
  30. exit 1
  31.