Back to Resources
Level
Script
Security
A disabled firewall on macOS can leave endpoints vulnerable to unauthorized network access and malicious traffic, especially when devices operate outside secure corporate environments. Detecting this issue proactively helps maintain a stronger security posture and reduces the chance of breaches.
This script uses the built-in socketfilterfw command to retrieve the firewall’s status on a macOS endpoint. If it’s enabled, the script reports success, and if it’s disabled, it raises an alert for immediate attention. You can set it up as a script-based monitor in Level so that you’re notified whenever the firewall is found to be off.
You can also integrate it into a scheduled Automation in Level, running periodic checks to enforce consistent security standards across your macOS fleet, ensuring no device remains unprotected.
1#!/bin/bash
2
3# This resource is provided as a convenience for Level users. We cannot
4# guarantee it will work in all environments. Please test before deploying
5# to your production environment. We welcome contributions to our community
6# library
7
8# Level Library
9# https://level.io/library/script-macos-monitor-firewall
10
11# Get the status of the firewall
12FIREWALL_STATUS=$(sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate)
13
14# Check if the firewall is enabled
15if [[ "$FIREWALL_STATUS" == *"Firewall is enabled"* ]]; then
16 echo "SUCCESS: Firewall is enabled."
17 exit 0
18else
19 echo "ALERT: Firewall is disabled."
20 exit 1
21fi
macOS Monitor - Firewall
This script checks the status of the macOS firewall by querying its global state and outputs a success message if the firewall is enabled or an alert if it is disabled, ensuring system security is maintained.
Bash
100
Local system
Explore more automations, scripts, and policies to further enhance your IT operations.