Disable AirPort when Ethernet cable is connected

Mar 09, '10 07:30:00AM

Contributed by: hellomrzebra415

At my office, I needed to find a way to turn of the wireless network when someone plugged in their network cable. I also did not want them to be able to turn the wireless network back on until the network cable was unplugged. I came up with the fallowing solution.

I created a launchDaemon called com.companyname.ethernetmonitor, and saved it in /System » Library » LaunchDaemons:

<?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.companyname.ethernetmonitor</string>
  <key>ProgramArguments</key>
  <array>
    <string>/Library/Scripts/CompanyName/turnOffAirport.sh</string>
  </array>
  <key>WatchPaths</key>
  <array>
    <string>/Library/Preferences/SystemConfiguration</string>
  </array>
</dict>
</plist>
This will watch the System Configurations folder for changes. This folder changes when you plug in a network cable, turn on AirPort, etc. When it changes, a script called turnOffAirport.sh, stored in /Library/Scripts, is run to see if the Ethernet connection has a company IP address:
#!/bin/sh
if ifconfig en0 | grep 155.144; 
then /usr/sbin/networksetup -setairportpower off
else
exit 0
fi
This helps keep the user from grabbing two IPs (our wireless and wired network use the same set of IPs), and also helps prevent a few other odd issues when a user is connected to both wireless and Ethernet networks.

Comments (28)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20100305114751547