Wake On Lan All dhcp leases via shell



  • Hi.

    Wake On Lan All dhcp leases via shell:

    wol-dhcpleases.sh : a shell script for wake on lan (wol) all dhcp leases

    The code:

    #!/bin/sh
    # wol-dhcpleases.sh
    # wol all dhcp leases via all interfaces
    # by javcasta - 2016 - https://javcasta.com
    
    BROADCAST=$(ifconfig | grep broadcast | cut -d' ' -f 6)
    DHCPLEASES=$(cat /var/dhcpd/var/db/dhcpd.leases | grep "hardware ethernet" | cut -d ' ' -f 5 | sort -u | sed "s|;||")
    for LAMAC in $DHCPLEASES; do
       echo "wake on lan:  ${LAMAC}"
       for ELBROADCAST in $BROADCAST; do
           /usr/local/bin/wol -i ${ELBROADCAST} ${LAMAC}
       done
    done
    

    Tested in pfSense 2.3.2_1

    Regards.