Skip to content
Snippets Groups Projects
Verified Commit ad1dc51b authored by David Beniamine's avatar David Beniamine
Browse files

Get ip from dhcp lease

parent b0cf5dd6
Branches
No related tags found
No related merge requests found
...@@ -16,6 +16,11 @@ ...@@ -16,6 +16,11 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # 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) IP=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1)
broadcast=$(ip a | awk '/inet.*eth1/ {print $4}' | 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) 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 | \ ...@@ -25,7 +30,7 @@ netcat -k -l $IP 9999 | \
if [ $(echo "$MAC" | egrep -c "^([0-9a-f]{2}:?){6}$") -eq 1 ] if [ $(echo "$MAC" | egrep -c "^([0-9a-f]{2}:?){6}$") -eq 1 ]
then then
wakeonlan -i $broadcast "$MAC" wakeonlan -i $broadcast "$MAC"
bootedip=`arp | grep "$MAC" | awk '{print $1}'` bootedip=`getip $MAC`
echo "$bootedip" | netcat $subnet.51 9999 echo "$bootedip" | netcat $subnet.51 9999
fi fi
done done
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment