|
Line
Link Here
|
|
|
|
++ arping.sh 2007-09-24 00:04:10.000000000 -0600 |
|
Lines 46-52
Link Here
|
| 46 |
# If neither arping (net-misc/iputils) or arping2 (net-analyzer/arping) |
46 |
# If neither arping (net-misc/iputils) or arping2 (net-analyzer/arping) |
| 47 |
# is installed then we return 1 |
47 |
# is installed then we return 1 |
| 48 |
arping_address_exists() { |
48 |
arping_address_exists() { |
| 49 |
local iface="$1" ip="${2%%/*}" mac="$3" foundmac= i= w= |
49 |
local iface="$1" ip="${2%%/*}" mac="$3" foundmac= i= w= ipndot= |
| 50 |
# We only handle IPv4 addresses |
50 |
# We only handle IPv4 addresses |
| 51 |
[[ ${ip} != *.*.*.* ]] && return 1 |
51 |
[[ ${ip} != *.*.*.* ]] && return 1 |
|
Lines 61-78
Link Here
|
| 61 |
arping_sleep |
61 |
arping_sleep |
| 62 |
local ifvar=$(bash_variable "${iface}") |
62 |
local ifvar=$(bash_variable "${iface}") |
|
|
63 |
|
| 64 |
for i in ${ip//./ } ; do |
| 65 |
if [[ ${#i} == "2" ]] ; then |
| 66 |
ipndot="${ipndot}0${i}" |
| 67 |
elif [[ ${#i} == "1" ]] ; then |
| 68 |
ipndot="${ipndot}00${i}" |
| 69 |
else |
| 70 |
ipndot="${ipndot}${i}" |
| 71 |
fi |
| 72 |
done |
| 73 |
|
| 74 |
local source="arping_source_${ipndot}" |
| 75 |
source="${!source}" |
| 76 |
[[ -z ${source} ]] && source="${arping_source:-0}" |
| 77 |
|
| 63 |
w="arping_wait_${ifvar}" |
78 |
w="arping_wait_${ifvar}" |
| 64 |
w="${!w}" |
79 |
w="${!w}" |
| 65 |
[[ -z ${w} ]] && w="${arping_wait:-3}" |
80 |
[[ -z ${w} ]] && w="${arping_wait:-3}" |
| 66 |
if [[ -x /sbin/arping ]] ; then |
81 |
if [[ -x /usr/sbin/arping2 ]] ; then |
| 67 |
foundmac=$(arping -c 2 -w "${w}" -D -f -I "${iface}" \ |
|
|
| 68 |
"${ip}" 2>/dev/null \ |
| 69 |
| sed -n 's/.*\[\([^]]*\)\].*/\U\1/p') |
| 70 |
elif [[ -x /usr/sbin/arping2 ]] ; then |
| 71 |
for (( i=0; i<w; i++ )) ; do |
82 |
for (( i=0; i<w; i++ )) ; do |
| 72 |
foundmac=$(arping2 -r -0 -c 1 -i "${iface}" \ |
83 |
if [[ ${source} == "0" ]] ; then |
| 73 |
"${ip}" 2>/dev/null) |
84 |
foundmac=$(arping2 -r -0 -c 1 -i "${iface}" \ |
|
|
85 |
"${ip}" 2>/dev/null) |
| 86 |
else |
| 87 |
foundmac=$(arping2 -r -S ${source} -c 1 -i "${iface}" \ |
| 88 |
"${ip}" 2>/dev/null) |
| 89 |
fi |
| 74 |
if [[ $? == "0" ]] ; then |
90 |
if [[ $? == "0" ]] ; then |
| 75 |
foundmac=$(echo "${foundmac}" \ |
91 |
foundmac=$(echo "${foundmac}" \ |
| 76 |
| tr '[:lower:]' '[:upper:]') |
92 |
| tr '[:lower:]' '[:upper:]') |
|
Lines 80-85
Link Here
|
| 80 |
fi |
96 |
fi |
| 81 |
foundmac= |
97 |
foundmac= |
| 82 |
done |
98 |
done |
|
|
99 |
elif [[ -x /sbin/arping ]] ; then |
| 100 |
if [[ ${source} == "0" ]] ; then |
| 101 |
foundmac=$(arping -c 2 -w "${w}" -D -f -I "${iface}" \ |
| 102 |
"${ip}" 2>/dev/null \ |
| 103 |
| sed -n 's/.*\[\([^]]*\)\].*/\U\1/p') |
| 104 |
else |
| 105 |
foundmac=$(arping -c 2 -w "${w}" -s ${source} -f -I "${iface}" \ |
| 106 |
"${ip}" 2>/dev/null \ |
| 107 |
| sed -n 's/.*\[\([^]]*\)\].*/\U\1/p') |
| 108 |
fi |
| 83 |
fi |
109 |
fi |
| 84 |
[[ -z ${foundmac} ]] && return 1 |
110 |
[[ -z ${foundmac} ]] && return 1 |