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}'`
[ ! -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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment