diff --git a/wol/scripts/sendmac.sh b/wol/scripts/sendmac.sh
index 1f7ac2a45e675f471f8847752a724fd44a4ea2d5..80ed7e99050278c07f547b937ee25ae689ee4a8f 100755
--- a/wol/scripts/sendmac.sh
+++ b/wol/scripts/sendmac.sh
@@ -22,5 +22,8 @@ KPID=`ps aux | grep \'$netcat\' | awk '{print $2}'`
 [ ! -z "$KPID" ] && kill $KPID
 
 subnet=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1 | cut -d . -f 1-3)
-echo "$1" | netcat $subnet.52 9999
+host=$subnet.52
+port=9999
+
+echo "$1" | netcat $host $port
 $netcat
diff --git a/wol/scripts/wakeonlanservice.sh b/wol/scripts/wakeonlanservice.sh
index 6fd4565aa51a542589451c5f31f8637a0d70370f..d742a975150fb7808b5f18635a43a72d3a55ca28 100755
--- a/wol/scripts/wakeonlanservice.sh
+++ b/wol/scripts/wakeonlanservice.sh
@@ -24,18 +24,26 @@ getip(){
 IP=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1)
 broadcast=$(ip a | awk '/inet.*eth1/ {print $4}' | cut -d / -f 1)
 subnet=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1 | cut -d . -f 1-3)
+host=$subnet.51
+port=9999
+
 while true
 do
-    MAC=`netcat -l $IP 9999`
+    MAC=`netcat -l $IP $port`
     #echo "$MAC"
     if [ $(echo "$MAC" | egrep -c "^([0-9a-f]{2}:?){6}$") -eq 1 ]
     then
         wakeonlan -i $broadcast "$MAC"
         sleep 3
-        bootedip=`getip $MAC`
-        ping -c 3 $bootedip || bootedip=""
-        #echo "Sending ip"
-        echo "$bootedip" | netcat $subnet.51 9999
-        #echo "Done"
+        IPS=`getip $MAC`
+        for ip in $IPS
+        do
+            ping -c 3 $ip
+            if [ $? -eq 0 ]
+            then
+                echo "$ip" | netcat $host $port
+                break
+            fi
+        done
     fi
 done