Skip to content

Instantly share code, notes, and snippets.

@fannyhasbi
Created December 6, 2024 01:05
Show Gist options
  • Save fannyhasbi/81ec7c435ecebb6c9e32348a66ea735d to your computer and use it in GitHub Desktop.
Save fannyhasbi/81ec7c435ecebb6c9e32348a66ea735d to your computer and use it in GitHub Desktop.
disable any wired network with USB or LAN as its name
#!/bin/bash
check_wired_network() {
networkServices=$(networksetup -listallnetworkservices | tail -n +2)
while IFS= read -r service; do
if [[ "$service" == \** ]]; then
continue
fi
if [[ "$service" == *"USB"* || "$service" == *"LAN"* ]]; then
networksetup -setnetworkserviceenabled "$service" off
if [ $? -eq 0 ]; then
echo "Successfully disabled: $service"
else
echo "Failed to disable: $service"
fi
fi
done <<< "$networkServices"
}
check_wired_network
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment