Category filter

Scripts to manage Wi-Fi network settings on macOS devices

The Execute Custom Script action provides an easy way to push customized settings and configurations to the devices over the air. This document includes different scripts for enabling, managing and modifying Wi-Fi connections and associated network settings for macOS devices.

How to add a preferred Wi-Fi network?

The command networksetup –addpreferredwirelessnetworkatindex adds a given network to the list of preferred networks at the specified index. It takes the following form:

networksetup -addpreferredwirelessnetworkatindex en0 Network_SSID Index_Number Network_Security_Type Network_Password

en0 – Corresponds to the hardware port for Wi-Fi

Network_SSID – Network Name

Index_Number – The preferred network index to be assigned to the network. It can take the integer values 0, 1, 2, etc.

Network_Security_Type – The network security type for the network such as WEP, WPA/WPA2, etc.

Network_Password – Specifies the network password.

How to join a given Wi-Fi network?

You can configure a device to join a given network by embedding the network credentials along with the networksetup command.

networksetup -setairportnetwork en0 Network_SSID Network_Password

If the specified network credentials are correct, the device connects to the given network instantly.

How to remove a preferred Wi-Fi network?

Suppose you want to remove a given network from the list of the preferred networks. You can use the networksetup –removepreferredwirelessnetwork command to do it.

The command takes the following form:

networksetup -removepreferredwirelessnetwork en0 Network_SSID

How to secure Wi-Fi settings?

You can restrict modification of Wi-Fi network settings to Administrator users using airport commands such as

RequireAdminIBSS=YES/NO

RequireAdminPowerToggle=YES/NO

RequireAdminNetworkChange=YES/NO

These commands mandate admin authentication to change the specified Wi-Fi settings on the device. You can modify the parameter values (YES or NO) for these commands to suit your requirements.

How to disable/enable Wi-Fi?

You can execute the following script when you want to disable the Wi-Fi network connections to the device completely.

Note:


While you disable Wi-Fi, make sure the device has a connection to other interfaces such as Ethernet. Otherwise, the device loses its connectivity. The Wi-Fi icon on the menu bar will be disabled, and the user cannot turn it on. The wireless network connectivity is disconnected until it is re-enabled.


To enable Wi-Fi,

How to turn on/off Wi-Fi?

To turn off Wi-Fi,

Note:


Executing this script toggles off the Wi-Fi network at the menu bar. However, the user can toggle it on from the device to regain network connectivity.


To turn on Wi-Fi,

How to retrieve the name of the current Wi-Fi network connected to the device?

Suppose you want to identify the Wi-Fi network to which the device is connected. The following script helps to retrieve the SSID of the current Wi-Fi network connected to the device.

How to get Wi-Fi network info?

You can obtain the DHCP configuration for the Wi-Fi interface using the following script. It retrieves all the information such as IP address, subnet mask, router, Wi-Fi ID etc.

How to identify if Wi-Fi network service is enabled?

For a device that can connect to one or more network interfaces, this script helps the admin determine if the Wi-Fi network is enabled.

How to set up search domains for the Wi-Fi interface?

Specifying the search domains helps the user to redirect to the websites and servers automatically without entering the complete address.

How to configure proxy settings for Wi-Fi?

Proxy server settings that can be configured using scripts include:

Set up automatic proxy

Configure domains that can bypass proxy

Note:


You can specify any number of domains. Each of them should be separated using a space.

Set DNS servers for Wi-Fi

Set up web proxy

In place of authenticated, you can specify either ON/OFF to enable or disable authenticated proxy support. You must specify the username and password if authentication is enabled.

Set up web proxy state

Retrieve the web proxy state

  • Sample Script Repository