Turn off Airport/Wireless script 10.7 help.

bentoms
Release Candidate Programs Tester

Hi guys,

I used a slightly modified version of the turn airport off script from the resource kit to.. erm.. turn off the airport.

It looks like apple have "fixed" 10.7, so instead of issuing:

/usr/bin/networksetup -setairportpower *HardwarePortName* off

You now need to do the following:

/usr/bin/networksetup -setairportpower *DeviceName* off

*DeviceName* is listed when you run, 
/usr/sbin/networksetup -listallhardwareports

So i tried: 
/usr/sbin/networksetup -listallhardwareports | awk '/^Hardware Port: "$checkWireless"/,/^Ethernet Address/' | head -2 | tail -1 | cut -c 9-

where checkWireless is set using the following:
checkWireless=$(networksetup -listallhardwareports | egrep "Hardware Port: (Air|Wi-)" | cut -c 16-) 

But the variable does not seem to be passing. script below.. maybe there is a better way?

In context below:

if [[ "$OS" == "10.4" ]]; then
# If OS is 10.4.x run the following to turn off Wireless...
echo "Turning off the Wireless for OS $OS..."
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setairportpower off
exit 0
elif [[ "$OS" == "10.5" ]]; then
# If OS is 10.5.x run the following to turn off Wireless...
echo "Turning off the Wireless for OS $OS..."
/usr/sbin/networksetup -setairportpower off
exit 0
elif [[ "$OS" == "10.6" ]]; then
# If OS is 10.6.x run the following to turn off Wireless...
echo "Turning off the Wireless for OS $OS..."
/usr/sbin/networksetup -setairportpower "$checkWireless" off
exit 0
elif [[ "$OS" == "10.7" ]]; then
# If OS is 10.7.x run the following to turn off Wireless...
checkWireless=$(networksetup -listallhardwareports | egrep "Hardware Port: (Air|Wi-)" | cut -c 16-)
# First we need to get the Wi-Fi device's name
wifiDevice=/usr/sbin/networksetup -listallhardwareports | awk '/^Hardware Port: "$checkWireless"/,/^Ethernet Address/' | head -2 | tail -1 | cut -c 9-
echo "Wi-fI Turning off the Wireless for OS $OS..."
/usr/sbin/networksetup -setairportpower "$wifiDevice" off
exit 0
fi

10 REPLIES 10

bentoms
Release Candidate Programs Tester

Nvm.

Thinking about this the name returned from /usr/bin/networksetup -listallhardwareports for the wireless card will always be Airport pre 10.7 & Wi-Fi on 10.7.

So no need for this step.

Regards,

Ben.

golbiga
Contributor III
Contributor III

/usr/sbin/networksetup -setnetworkserviceenabled Wi-Fi off

Allen

bentoms
Release Candidate Programs Tester

That will disable the service right?

I'm merely looking at turning off the airport.

Regards,

Ben.

golbiga
Contributor III
Contributor III

Yeah, that disables it. On my firstboot if its not a notebook it gets disabled.

Thanks
Allen

nessts
Valued Contributor II

unless of course somebody renames it, because they like airport better.

--
Todd Ness
Technology Consultant/Non-Windows Services
Americas Regional Delivery Engineering
HP Enterprise Services

bentoms
Release Candidate Programs Tester

The hardwareport name is what the OS is calling the Wireless device.

The service is what's renamable.

Regards,

Ben.

bentoms
Release Candidate Programs Tester

Script has been posted here:  http://wp.me/p12A66-55

This script will: 1. Enable the wireless service if it's not been enabled. 2. Clear any set DNS servers & search domains (can be turned off for 10.4, reasoning is that 10.5+ can receive DNS from DHCP) 3. Turns off the wireless card.
The script itself has been built from a few scripts contained within Caspers Resource Kit & then modified for 10.7 by myself.

Works on 10.4+ & can help those with slow ad logins when off the office lan, http://wp.me/p12A66-2Z

sean
Valued Contributor

networksetup will allow you to use either "Hardware Port:" or "Device:" to turn the power on or off

Hardware Port: AirPort Device: en2

You can pull the device name from ioreg, regardless of OS, so it doesn't matter that Lion calls it one thing and previous versions another.

ioreg -l -n ARPT at 0 -r | grep "BSD Name" | cut -d """ -f 4

Sean

bentoms
Release Candidate Programs Tester

thanks Sean!

However, it does see, that on 10.7 it has to be "Device" & not "Hardware Port"

Even the man pages are confuseds though as in the man page synopsis it seems to show this behaviour:  [-setairportpower device on | off]

but in the description it says:

-getairportpower hardwareport Displays whether Wi-Fi power is on or off.

Maybe i'll file a bug report...

sean
Valued Contributor

That may be related to ioreg not having an equivalent to "AAPL,slot-name" for the wireless device.

Snow Leopard and Leopard have: "AAPL,slot-name" = <"AirPort">

Lion has nothing to match this. Probably worth mentioning if you are going to bug report it.

Sean