Code

Moving finalized
[gosa.git] / gosa-core / contrib / scripts / net-resolver.sh
1 #!/bin/sh
3 # Check for number of parameters
4 if [ $# -ne 1 ]; then
5         echo Usage: $(basename $0) dns-name
6         exit 1
7 fi
9 # Check for needed commands
10 for cmd in /usr/bin/host /usr/bin/fping /usr/sbin/arp; do
11         if [ ! -x $cmd ]; then
12                 echo $cmd command not found - aborting
13                 exit 2
14         fi
15         eval $(echo ${cmd##*/}=$cmd)
16 done
18 mac=""
19 ip=$(LANG=C $host $1 | grep address | head -n1 | sed 's/^.*[^0-9]\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/g')
20 if [ -z "$ip" ]; then
21         echo ";"
22         exit 0
23 fi
24 if $fping -c1 -r3 -t500 $ip &> /dev/null; then
25         mac=$($arp -n | awk "/^$ip/ {print \$3}")
26 fi
27 echo "$ip;$mac"