Posted on 12-17-2014 10:03 AM
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
Posted on 12-17-2014 10:06 AM
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
Posted on 12-17-2014 10:21 AM
Try this...
networksetup -setairportpower en0 off
Posted on 12-17-2014 10:26 AM
AirPort isn't always en0 FYI, can't make that assumption.
Somewhere I have a code snippet which detects which port is WiFi...
Posted on 12-17-2014 10:36 AM
This removes the kernel extension for the wireless
srm -rf /System/Library/Extensions/IO80211Family.kext
touch /System/Library/Extensions/
Posted on 12-17-2014 10:37 AM
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:
Posted on 12-17-2014 10:37 AM
networksetup -setairportpower $(networksetup -listallhardwareports | awk '/AirPort|Wi-Fi/{getline; print $NF}') off
Posted on 12-17-2014 12:00 PM
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
Posted on 12-17-2014 12:10 PM
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
Posted on 12-17-2014 12:17 PM
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.
Posted on 01-04-2015 11:28 AM
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/
Posted on 07-27-2017 04:13 AM
We use this Configuration Profile to disable the Wi-Fi interface on our desktop Macs.
Posted on 08-01-2017 02:44 PM
@mark.mahabir - Can you elaborate on that? How do you use a mobileconfig for desktops?
Posted on 08-01-2017 03:06 PM
@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.