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

[Need test] Handle multiple IPs in dhcp lease

Also small refactor to avoid constants in code
parent 3e9d0868
No related branches found
No related tags found
No related merge requests found
...@@ -22,5 +22,8 @@ KPID=`ps aux | grep \'$netcat\' | awk '{print $2}'` ...@@ -22,5 +22,8 @@ KPID=`ps aux | grep \'$netcat\' | awk '{print $2}'`
[ ! -z "$KPID" ] && kill $KPID [ ! -z "$KPID" ] && kill $KPID
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)
echo "$1" | netcat $subnet.52 9999 host=$subnet.52
port=9999
echo "$1" | netcat $host $port
$netcat $netcat
...@@ -24,18 +24,26 @@ getip(){ ...@@ -24,18 +24,26 @@ getip(){
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)
host=$subnet.51
port=9999
while true while true
do do
MAC=`netcat -l $IP 9999` MAC=`netcat -l $IP $port`
#echo "$MAC" #echo "$MAC"
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"
sleep 3 sleep 3
bootedip=`getip $MAC` IPS=`getip $MAC`
ping -c 3 $bootedip || bootedip="" for ip in $IPS
#echo "Sending ip" do
echo "$bootedip" | netcat $subnet.51 9999 ping -c 3 $ip
#echo "Done" if [ $? -eq 0 ]
then
echo "$ip" | netcat $host $port
break
fi
done
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