Skip to content
Snippets Groups Projects
Commit 8ade577c authored by ERIK ALEXANDRE PUCCI's avatar ERIK ALEXANDRE PUCCI Committed by Danilo K. S. Yorinori
Browse files

common.sh: Created getNetworkInterface() to obtain the default route NIC


The function checks all network interface controllers (NICs) set as the
default route, using ping(1) to test them with two root servers (in case one
is off). The first NIC connected to the Internet is chosen.

Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
Signed-off-by: default avatarDanilo K. S. Yorinori <danilok@c3sl.ufpr.br>
parent 1c95978a
No related branches found
No related tags found
No related merge requests found
......@@ -70,3 +70,21 @@ function tryWget(){
--proxy-password="${ppasswd}" \
$* || return 1
}
#------------------------------------------------------------------------------
# function: getNetworkInterface
# Get the network interface which the client must bind to (in case there is
# more than one default route) and the collect will use to obtain the MAC
# address.
function getNetworkInterface()
{
interface=""
for interface in $(route | grep default | awk '{print $NF}'); do
# Send ICMP ECHO_REQUEST to root server I or J
if ping -c 1 -I ${interface} 192.36.148.17 > /dev/null 2>&1 ||
ping -c 1 -I ${interface} 192.58.128.30 > /dev/null 2>&1 ; then
break
fi
done
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment