Created
September 29, 2024 16:40
-
-
Save SwiftyAlex/b394f786c4060b27e7e839f7c2b3cc74 to your computer and use it in GitHub Desktop.
Network Checker
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 | |
# Define an array of known SSIDs | |
KNOWN_SSIDS=("☕️" "Network2" "Network3") # Replace with your network names | |
# Get the current Wi-Fi SSID | |
CURRENT_SSID=$(system_profiler SPAirPortDataType | grep -A2 'Status: Connected' | tail -n1 | sed 's/:$//' | xargs) | |
echo $CURRENT_SSID | |
# Check if CURRENT_SSID is in KNOWN_SSIDS | |
FOUND=0 | |
for SSID in "${KNOWN_SSIDS[@]}"; do | |
if [[ "$CURRENT_SSID" == "$SSID" ]]; then | |
FOUND=1 | |
break | |
fi | |
done | |
if [ $FOUND -eq 1 ]; then | |
echo "Connected" | |
exit 0 # Connected to one of the known networks | |
else | |
echo "Not connected" | |
exit 1 # Not connected to any of the known networks | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment