network_service_refresh_macos.sh - limehawk/rmm-scripts GitHub Wiki
network_service_refresh_macos.sh
Toggles all network services off and on to refresh connections.
Overview
This script toggles all network services off and on to refresh connections. Useful for resolving network connectivity issues without requiring a full system restart. Restores original enabled/disabled state after refresh.
Purpose
Refreshes all network services on macOS by toggling them off and on. Preserves the original enabled/disabled state of each service. Useful for resolving DHCP lease issues, DNS problems, or general network connectivity problems.
Prerequisites
- Root/sudo access required
- macOS 10.14 or later
- networksetup command available
Configuration
Required Inputs
- TOGGLE_DELAY: Seconds to wait between off/on toggle (default: 2)
Behavior
- Lists all network services
- For each service: a. Records initial enabled/disabled state b. Disables the service c. Waits briefly d. Enables the service e. Restores original state if it was disabled
- Reports final status
Security Notes
- No secrets exposed in output
- Runs with elevated privileges (sudo required)
- Temporarily disrupts network connectivity
Exit Codes
- 0 - Success
- 1 - Failure
Example Output
[ INPUT VALIDATION ]
--------------------------------------------------------------
Toggle Delay : 2s
Running as root : Yes
[ NETWORK SERVICES ]
--------------------------------------------------------------
Found 3 network service(s)
[ OPERATION ]
--------------------------------------------------------------
Processing: Wi-Fi
Toggling 'Wi-Fi' off...
Toggling 'Wi-Fi' on...
Processing: Bluetooth PAN
Toggling 'Bluetooth PAN' off...
Toggling 'Bluetooth PAN' on...
Restoring 'Bluetooth PAN' to Disabled state...
Processing: Thunderbolt Bridge
Toggling 'Thunderbolt Bridge' off...
Toggling 'Thunderbolt Bridge' on...
[ RESULT ]
--------------------------------------------------------------
Status : Success
Services Processed : 3
[ FINAL STATUS ]
--------------------------------------------------------------
Network services have been refreshed.
Current network service status:
An asterisk (*) denotes that a network service is disabled.
Wi-Fi
*Bluetooth PAN
Thunderbolt Bridge
[ SCRIPT COMPLETED ]
--------------------------------------------------------------
Version History
- 1.0.0 (November 2024) - Initial release
Links
- View Script Source
- Scripts - Back to script index