Posted on 02-02-2016 05:00 PM
Pretty straightforward. I'm trying to enable a disabled upon wired connect setting that does just that. When an Ethernet connection is present it disabled Wifi. Any ideas on the best way to tackle this?
Posted on 02-02-2016 06:22 PM
You will need to test it to ensure it does what you need it to. I've used this in the past and it has worked reasonably well for my needs.
https://jamfnation.jamfsoftware.com/discussion.html?id=1441#responseChild50056
Posted on 02-04-2016 01:03 AM
I've setup 2 network locations , 1 for 'inoffice' (ethernet) and another for 'outofoffice' (WiFi)
Then you can use the command : networksetup -switchlocation [networklocation]
I've scoped a policy using the 'network state change' trigger
cheers
Posted on 02-04-2016 10:18 AM
We needed a way to have only one interface to be active at a time, unless a tech needs to assist.
How it works:
LaunchDaemon has a WatchPath of /Library/Preferences/SystemConfiguration/preferences.plist.old which gets triggered by any Ethernet Change or WiFi change, other things do cause this to be triggered but this was the least triggered method I found. Upon a triggered Watch Path it runs the Script which checks to see if the Ethernet is connected and has an IP and if so it disables the WiFi and if not then Wifi is enabled.
LaunchDaemon Contents: com.network-toggle.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.uhg.network-toggle</string>
<key>ProgramArguments</key>
<array>
<string>/Library/Scripts/CompanyName/Network-Toggle.sh</string>
</array>
<key>AbandonProcessGroup</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>WatchPaths</key>
<array>
<string>/Library/Preferences/SystemConfiguration/preferences.plist.old</string>
</array>
</dict>
</plist>
Script Contents: Network-Toggle.sh
networkAdapters=$(networksetup -listallnetworkservices | grep -v "Bluetooth" | grep -v "FireWire" | grep -v "asterisk" | grep -v "Thunderbolt Bridge" | grep -v "iPhone" | tr -d "")
NEWLINE="
"
IFS=$NEWLINE
adapterArray=()
for theAdapter in $networkAdapters
do
adapterCheck=networksetup -getinfo $theAdapter | grep '[0-9]
.[0-9].[0-9].[0-9]*'
if [ "$adapterCheck" != "" ]; then
echo $theAdapter $adapterCheck
adapterArray+=($theAdapter)
fi
done
ethernetCheck=echo ${adapterArray[@]} | grep -i Ethernet
wifiCheck=echo ${adapterArray[@]} | grep -i Wi-Fi
if [ "$ethernetCheck" != "" ] && [ "$wifiCheck" != "" ]; then
/usr/sbin/networksetup -setairportpower en1 off
fi
if [ "$ethernetCheck" == "" ] && [ "$wifiCheck" == "" ]; then
/usr/sbin/networksetup -setairportpower en1 on
fi
For our techs to assist with a device or anyone needing the ability to have both interfaces active at the same time, we have a Self Service item that runs the following script, which gives them a dialog with a 15 Minute timer before the network toggle (WiFi Suppression) is activated again.
Disable Network Toggle 15 Minutes: Disable-Network-Toggle-15MinTimer.sh
DelayInSeconds=""
iconToUseParam="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericNetworkIcon.icns"
if [ "$4" != "" ] && [ "$DelayInSeconds" == "" ]; then
DelayInSeconds=$4
elif [ "$4" == "" ] && [ "$DelayInSeconds" == "" ]; then
DelayInSeconds=900
fi
/bin/launchctl unload /Library/LaunchDaemons/com.uhg.network-toggle.plist 2> /dev/null
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType hud -icon "$iconToUseParam" -alignHeading center -title "Network Toggle Disabled" -description "Disable Network Toggle allows for both interfaces to be active at the same time." -timeout "$DelayInSeconds" -countdown -alignCountdown left -button1 "Finished" -lockHUD -windowPosition ur
launchctl load /Library/LaunchDaemons/com.network-toggle.plist
exit 0
I hope this helps!