diff --git a/aping.sh b/aping.sh index fcbd91d..3d34e0f 100755 --- a/aping.sh +++ b/aping.sh @@ -33,17 +33,18 @@ withLoop(){ echo "Pinging ${site} until a connection is reached" ${pingcmd} ${site} &>/dev/null - if [ $? = "2" ];then + ping_result=$? + if [ $ping_result = "2" ];then echo echo "The internet is not working:(" sleep 1 - elif [ $? = "1" ];then + elif [ $ping_result = "0" ];then if [ "${play_sound}" = "true" ];then - ${sound_player} ${player_opts[*]} ${sound_file} "${sound_message}" & + ${sound_player} "${player_opts[@]}" ${sound_file} "${sound_message}" & fi - lanip=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p') + lanip=$(ip -o -4 addr show | awk '$2 != "lo" {sub(/\/.*/, "", $4); print $4}') pubip=$(curl -s ifconfig.me) clear @@ -79,20 +80,21 @@ withoutLoop(){ echo "Pinging ${site}" ${pingcmd} ${site} &>/dev/null + ping_result=$? - if [ $? = "2" ];then + if [ $ping_result = "2" ];then echo echo "The internet is not working :(" - elif [ $? = "1" ];then + elif [ $ping_result = "0" ];then if [ "${play_sound}" = "true" ];then - ${sound_player} "${player_opts}" "${sound_file}" "${sound_message}" & + ${sound_player} "${player_opts[@]}" "${sound_file}" "${sound_message}" & fi - lanip=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p') + lanip=$(ip -o -4 addr show | awk '$2 != "lo" {sub(/\/.*/, "", $4); print $4}') pubip=$(curl -s http://whatismijnip.nl |cut -d " " -f 5) clear