OSX Tips – Turn off WiFi from the command line

AirportFollowing on from my previous post where we turned off OSX’s energy saver from the command line, this tip will show you how to disable WiFi/Airport from the same place.

To turn off:

networksetup -setairportpower en1 off

and to turn back on:

networksetup -setairportpower en1 on

You may want to be a bit smarter and use a script to discover the port used by your WiFi card and automate things somewhat:

#!/bin/bash

# get current wifi device
CURRENT_DEVICE=$(networksetup -listallhardwareports | awk '$3=="Wi-Fi" {getline; print $2}')
echo "Current Wi-Fi Device = '$CURRENT_DEVICE'"

# turn off wifi
networksetup -setairportpower $CURRENT_DEVICE off

And to turn it back on again:

#!/bin/bash

# get current wifi device
CURRENT_DEVICE=$(networksetup -listallhardwareports | awk '$3=="Wi-Fi" {getline; print $2}')
echo "Current Wi-Fi Device = '$CURRENT_DEVICE'"

# turn on wifi
networksetup -setairportpower $CURRENT_DEVICE on
Share Button

One thought on “OSX Tips – Turn off WiFi from the command line

  1. Pingback: OSX Tips – Turn off sleep mode from the command line | DGKApps – Blog

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>