Skip to main content
Question

Disable WiFi

  • December 17, 2014
  • 13 replies
  • 61 views

Forum|alt.badge.img+3

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

Forum|alt.badge.img+17
  • Honored Contributor
  • December 17, 2014

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


Forum|alt.badge.img+13
  • Contributor
  • December 17, 2014

Try this...
networksetup -setairportpower en0 off


RobertHammen
Forum|alt.badge.img+28
  • Esteemed Contributor
  • December 17, 2014

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

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


Forum|alt.badge.img+13
  • Contributor
  • December 17, 2014

This removes the kernel extension for the wireless

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

Forum|alt.badge.img+31
  • Hall of Fame
  • December 17, 2014

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_networks


mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • December 17, 2014
networksetup -setairportpower $(networksetup -listallhardwareports | awk '/AirPort|Wi-Fi/{getline; print $NF}') off

Forum|alt.badge.img+12
  • Contributor
  • December 17, 2014

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

Forum|alt.badge.img+16
  • Valued Contributor
  • December 17, 2014

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
Forum|alt.badge.img+35
  • Hall of Fame
  • December 17, 2014

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
Forum|alt.badge.img+35
  • Hall of Fame
  • January 4, 2015

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
Forum|alt.badge.img+15
  • Jamf Heroes
  • July 27, 2017

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


Forum|alt.badge.img+5
  • Contributor
  • August 1, 2017

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


stevewood
Forum|alt.badge.img+35
  • Hall of Fame
  • August 1, 2017

@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.