Disable WiFi

mmartinez
New Contributor

Hello,

I need a script that can be ran that will allow our machine to disable WiFi. We use a network cable to get connected to the internet.

Thanks,

Marc

13 REPLIES 13

CasperSally
Valued Contributor II

Bet something here will help

http://www.google.com/search?q=jamfnation+disable+wifi&oq=jamfnation+disable+wifi&aqs=chrome..69i57.4089j0j4&sourceid=chrome&es_sm=122&ie=UTF-8&gws_rd=ssl

Johnny_Kim
Contributor II

Try this...
networksetup -setairportpower en0 off

RobertHammen
Valued Contributor II

AirPort isn't always en0 FYI, can't make that assumption.

Somewhere I have a code snippet which detects which port is WiFi...

jacob_salmela
Contributor II

This removes the kernel extension for the wireless

srm -rf /System/Library/Extensions/IO80211Family.kext
touch /System/Library/Extensions/

rtrouton
Valued Contributor III

This should allow the WiFi interface to be identified:

/usr/sbin/networksetup -listallhardwareports | awk '/^Hardware Port: Wi-Fi/,/^Ethernet Address/' | head -2 | tail -1 | cut -c 9-

I'm using that as part of this script:

https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/setting_preferred_wireless...

mm2270
Legendary Contributor II
networksetup -setairportpower $(networksetup -listallhardwareports | awk '/AirPort|Wi-Fi/{getline; print $NF}') off

acdesigntech
Contributor II

i toggle between wifi only and wired only. Works like a charm for me, and still allows laptop users to take their Mac home and be connected to home wifi, or starbucks wifi, etc.

## Is this a retina macbook? If so we need to reverse the en designations: en1 for wired, en0 for wireless
ModelType=`system_profiler SPHardwareDataType | grep -e "Model Identifier" | awk '{print substr($3,1,7)}'`
/usr/sbin/networksetup -listallhardwareports | grep "Thunderbolt Ethernet"
Thunderbolt=`echo $?`
if [ "$Thunderbolt" == "0" -a "$ModelType" == "MacBook" ]; then ##We have a retina, reverse the polarity!
    WiredEthernet="en1"
    WirelessEthernet="en0"
else
    WiredEthernet="en0"
    WirelessEthernet="en1"
fi

#############################################
#Check to see if Ethernet is connected
#############################################

sleep 10
checkActive=`ifconfig $WiredEthernet | grep status | cut -d ":" -f2` ## Ethernet is connected?
if [ "$checkActive" == " active" ]; then
    ## Turn off Airport
    networksetup -setairportpower $WirelessEthernet off
else
    networksetup -setairportpower $WirelessEthernet on
fi


#############################################
# Update the IP address in Casper immediately
#############################################
sleep 5
jamf log

exit 0

Look
Valued Contributor III

This is pretty much what I have been using for a while.

WFINT=$(networksetup -listallhardwareports | awk ' /Airport|Wi-Fi/ {getline; print $NF }')
if [ "$WFINT" != "" ]; then
echo "Disabling Wi-Fi on $WFINT"
networksetup -setairportpower $WFINT off
fi

stevewood
Honored Contributor II

I use the following script found at the bottom of this discussion: https://jamfnation.jamfsoftware.com/discussion.html?id=1441#respond

#!/bin/bash

##
# Define wireless interface "en" label.
wifiInterface=$(networksetup -listallhardwareports | grep 'Wi-Fi' -A1 | grep -o en.)
##
# Define wireless interface active status.
wifiStatus=$(ifconfig "${wifiInterface}" | grep 'status' | awk '{ print $2 }')
##
# Define wireless interface power status
wifiPower=$(networksetup -getairportpower "${wifiInterface}" | awk '{ print $4 }')
##
# Define non-wireless interface "en" labels.
ethernetInterface=$(networksetup -listallhardwareports | grep 'en' | grep -v "${wifiInterface}" | grep -o en.)
##
# Define non-wireless IP status.
ethernetIP=$(for i1 in ${ethernetInterface};do
  echo $(ifconfig "${i1}" | grep 'inet' | grep -v '127.0.|169.254.' | awk '{ print $2 }')
done)
##
# Disable active wireless interface if non-wireless interface connected.
if [[ "${ethernetIP}" && "${wifiStatus}" = "active" ]] || [[ "${ethernetIP}" && "${wifiPower}" = "On" ]]; then
  networksetup -setairportpower "${wifiInterface}" off
  touch /var/tmp/wifiDisabled; fi
##
# Enable inactive wireless interface if previously disabled by daemon.
if [[ "${ethernetIP}" = "" && "${wifiStatus}" = "inactive" ]] || [[ "${ethernetIP}" = "" && "${wifiPower}" = "Off" ]]; then
  if [[ -f "/var/tmp/wifiDisabled" ]]; then
    rm -f /var/tmp/wifiDisabled
    networksetup -setairportpower "${wifiInterface}" on; fi
fi

## update the JSS
checkjss=`/usr/sbin/jamf checkJSSConnection -retry 0 | grep "The JSS is available"`

if [ "$checkjss" == "The JSS is available." ]; then
    /usr/sbin/jamf log
fi

##
# Sleep to prevent launchd interpreting as a crashed process.
sleep 10
exit 0

Run via a LaunchDaemon that runs every 10 seconds. There's better ways to do this using crankd or other methods, but this works for me so I'm fine with it.

bentoms
Honored Contributor III
Honored Contributor III

We used to run the below @ logout, that way people would have to enable wireless to connect.

Another option would be to run the below via the JSS when on certain Network Segments using the Network change trigger. https://macmule.com/2011/09/09/how-to-turn-off-wireless-card/

mark_mahabir
Valued Contributor

We use this Configuration Profile to disable the Wi-Fi interface on our desktop Macs.

dmillertds
New Contributor III

@mark.mahabir - Can you elaborate on that? How do you use a mobileconfig for desktops?

stevewood
Honored Contributor II

@dmillertds a .mobileconfig file is simply the XML file exported out of Profile Manager for example. So you import that .mobileconfig file into Jamf Pro as a Configuration Profile and apply that to your desktop systems.