Skip to content

Instantly share code, notes, and snippets.

@sebnyberg
Created February 5, 2025 07:32
Show Gist options
  • Save sebnyberg/ab9812dcf436e1dc8cbe56481b208aed to your computer and use it in GitHub Desktop.
Save sebnyberg/ab9812dcf436e1dc8cbe56481b208aed to your computer and use it in GitHub Desktop.
poll for private IP
echo "nslookup-polling address until found on a private IP"
set +e # allow errors (for now)
counter=0
while true; do
for addr in 10 172.16 192.168 ; do
nslookup ${{ inputs.address }} | grep "IP Address: ${addr}" > /dev/null
if [ "$?" -eq 0 ]; then
exit 0
fi
done
echo "nslookup not resolving private IP, waiting another 5 seconds..."
sleep 5
# try reloading resolved
sudo systemctl daemon-reload
sudo systemctl restart systemd-networkd
sudo systemctl restart systemd-resolved
counter=$((counter + 1))
if [ $counter -gt 15 ]; then
echo "nslookup failed more than 15 times, giving up"
exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment