From ad1dc51b5dbf9e471cafa40b28895a86d97c0b71 Mon Sep 17 00:00:00 2001
From: David Beniamine <david.beniamine@tetras-libre.fr>
Date: Thu, 2 Aug 2018 08:59:01 +0200
Subject: [PATCH] Get ip from dhcp lease

---
 wol/scripts/wakeonlanservice.sh | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/wol/scripts/wakeonlanservice.sh b/wol/scripts/wakeonlanservice.sh
index 96ee0b6..6a5b53f 100755
--- a/wol/scripts/wakeonlanservice.sh
+++ b/wol/scripts/wakeonlanservice.sh
@@ -16,6 +16,11 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+getip(){
+    awk '/^lease/{IP=$2} /hardware ethernet/{gsub(";","",$3);if($3 == "'$1'"){print $3}}' \
+        < /var/lib/dhcp/dhcpd.leases
+}
+
 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)
@@ -25,7 +30,7 @@ netcat -k -l $IP 9999 | \
         if [ $(echo "$MAC" | egrep -c "^([0-9a-f]{2}:?){6}$") -eq 1 ]
         then
             wakeonlan -i $broadcast "$MAC"
-            bootedip=`arp | grep "$MAC" | awk '{print $1}'`
+            bootedip=`getip $MAC`
             echo "$bootedip" | netcat $subnet.51 9999
         fi
     done
-- 
GitLab