nmbd-finds-all-addresses.sh [plain text]
#! /bin/bash
SCRIPTBASE=${SCRIPTBASE:-$(cd $(dirname $0)/.. && pwd )}
. $SCRIPTBASE/common.sh || exit 2
if [ $cat <<EOF
Usage: nmbd-finds-all-addresses.sh
EOF
exit 1;
fi
NMBLOOKUP=${NMBLOOKUP:-/usr/bin/nmblookup}
IFCOUNT=${I5COUNT:-5}
failed=0
failtest()
{
failed=`expr $failed + 1`
}
setup_state()
{
local n=0
echo adding $IFCOUNT en0 aliases
while (($n < $IFCOUNT)) ; do
$ASROOT ifconfig en0 alias 192.168.$n.127 netmask 255.255.255.0
n=$(($n + 1))
done
}
remove_state()
{
local n=0
echo removing en0 aliases
while (($n < $IFCOUNT)) ; do
$ASROOT ifconfig en0 -alias 192.168.$n.127 netmask 255.255.255.0
n=$(($n + 1))
done
}
test_nmblookup()
{
local count=0
echo making sure we search on each alias
count=$(
$NMBLOOKUP $(basename $0) | \
awk '/192.168/ { print $0 }' | \
wc -l | awk '{print $1}'
)
echo searched $count subnets
(( $count == $IFCOUNT ))
}
setup_state
register_cleanup_handler remove_state
test_nmblookup || failtest
testok $0 $failed