Last active
August 25, 2019 18:22
-
-
Save TravisMullen/e661d37bb6e996b5a7b7d27da6f73710 to your computer and use it in GitHub Desktop.
Get IP and MAC Addy from *unix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LIMIT=90 # wait 90 increments | |
a=0 | |
# wait until network has connection (eval to 0 when connected) | |
while ! ifconfig en0 | grep -F 'inet' > /dev/null; do | |
a=$(($a+1)) | |
if [ "$a" -ge "$LIMIT" ]; then | |
echo "No network connection found after $LIMIT seconds, killing process." | |
exit 0 | |
fi | |
if [ "$a" -le 1 ] ; then | |
echo 'Waiting for network connection...' | |
fi | |
if [ $(( $a % 5 )) -eq 0 ] ; then | |
echo " still waiting... ($a seconds)." | |
fi | |
sleep 1 # set increment to 1 second | |
done | |
eventdate=$(date) | |
ipaddress=$(ifconfig en0 inet | awk 'NR==2 {print $2}') | |
macaddress=$(ifconfig en0 | awk 'NR==2 {print $2}') | |
echo | |
echo | |
echo "$eventdate" | |
echo '============================================================================' | |
echo "IP address: $ipaddress" | |
echo "MAC address: $macaddress" | |
echo '============================================================================' | |
echo | |
# do some ish | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment