Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.6: Add wireless networks from command line System 10.6
Snow Leopard only hintIn the past there have been several published hints on the /usr/sbin/networksetup command. However, until recently (well since 10.6.x) that command was not able to add passkeys to the keychain. I just received 500 new MacBooks to image in my enterprise and these brand new ones will only run 10.6. The rest of our deployment is still on 10.5.8 because we never had the desire to re-image 40 OS X Servers and 8,000 clients with 10.6.

So, I just modified my post image shell script to have a line that does a simple case statement and if it outputs 10.6* it executes this line of code:
/usr/sbin/networksetup -addpreferredwirelessnetworkatindex Airport my_ssid 0 my_security my_passkey
Where my_ssid is the SSID of your network, my_security is the level of encryption (WEP, WPA, WPA2, etc) and my_passkey is your encryption passkey for your wireless network. I've tested this out on my post image shell script on about 10 clients so far after imaging them with 10.6. So far it works pretty well, and is a key step in us not having any post configuration to do by hand after a machine is imaged.

I know this is a bit of an older hint since 10.6 has been out for a while now but I searched it did not find anything on this, then I read the manual page from the Apple Developer site and found that command.

[crarko adds: I haven't tested this one.]
    •    
  • Currently 4.13 / 5
  You rated: 1 / 5 (8 votes cast)
 
[13,543 views]  

10.6: Add wireless networks from command line | 12 comments | Create New Account
Click here to return to the '10.6: Add wireless networks from command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: Add wireless networks from command line
Authored by: karog on Oct 05, '10 08:58:18AM
I just did
networksetup -help | grep addpref
Usage: networksetup -addpreferredwirelessnetworkatindex <device name> <network> <index> <security type> [password]
Note the -addpreferredwirelessnetworkatindex, ie atindex rather than toindex.

[ Reply to This | # ]
10.6: Add wireless networks from command line
Authored by: neuralstatic on Oct 05, '10 10:40:45AM

good catch, you just saved a LOT of frustrated users.



[ Reply to This | # ]
10.6: Add wireless networks from command line
Authored by: crarko on Oct 05, '10 06:28:42PM

OK, I changed this in the hint.

Thanks for the catch!



[ Reply to This | # ]
10.6: Add wireless networks from command line
Authored by: DarthMagnus on Oct 05, '10 09:28:30AM

Convenient. I was just looking at this command because our IT department at my school uses WPA2 Enterprise authentication using an 802.1x profile and we have been having a ton of problems setting this up on the Macs. I was hoping that doing it programmatically would resolve these issues and stop people from saying silly things like they hate Macs.

Only problem is, I can't seem to get it to specify the 802.1x profile to use. Anyone have any ideas on this? Or is there a better way to go about deploying network configurations programmatically? Thanks!



[ Reply to This | # ]
10.6: Add wireless networks from command line
Authored by: tedw on Oct 05, '10 10:58:31AM
There are several options for importing/exporting 802.1x profiles listed on the networksetup man page (see here and search for 8021x). are they what you're looking for?

[ Reply to This | # ]
10.6: Add wireless networks from command line
Authored by: DarthMagnus on Oct 05, '10 06:07:39PM

Unfortunately, not quite. Those will work for getting the profiles imported into the Network preference pane, but not for telling the preferred network you set up to use the already-imported 802.1x profile. Also, I'm not sure if that even works for telling the 802.1x profile which certificates to use or not. Still testing on that part.



[ Reply to This | # ]
10.6: Add wireless networks from command line
Authored by: tom larkin on Oct 05, '10 09:48:32PM

Here is the newest man page if that helps

http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man8/networksetup.8.html



[ Reply to This | # ]
10.6: Add wireless networks from command line
Authored by: djseth on Oct 06, '10 07:11:43AM

Do you know if the command line trick works with networks that do not broadcast SSID? How do you make it the "preferred wireless" for that location?

Also, we really need to specify which 802.x profile to use too. Any help on this would be very much appreciated.



[ Reply to This | # ]
10.6: Add wireless networks from command line
Authored by: tom larkin on Oct 06, '10 07:33:58AM

Darthmangus-

You may want to look at the airport framework. It may help you with your issue.

look here:

bash-3.2# /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -h
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport AirPort v.528.1 (528.1.0)
Supported arguments:
 -z        --disassociate       Disassociate from any network
 -i[] --ibss=[]       Create IBSS
 -x        --xml                Print info as XML
 -s[] --scan=[]       Perform a wireless broadcast scan.
				   Will perform a directed scan if the optional  is provided
 -r   --repeats=      Repeat the command the specified number of times
 -A[] --associate=[]  Associate to network.
				   Will prompt for network name if arg is not specified
				   and if necessary, for a password if the network is using WEP or WPA.
				   The following additional arguments may be specified with this command:
                                  --bssid=     Specify BSSID to associate with
                                  --password=  Specify a WEP key or WPA password
 -I        --getinfo            Print current wireless status, e.g. signal info, BSSID, port type etc.
 -P   --psk=          Create PSK from specified pass phrase and SSID.
				   The following additional arguments must be specified with this command:
                                  --ssid=      Specify SSID when creating a PSK
 -c[] --channel=[]    Set arbitrary channel on the card
 -h        --help               Show this help



[ Reply to This | # ]
10.6: Add wireless networks from command line
Authored by: DarthMagnus on Oct 06, '10 09:46:04AM

I have looked at the airport framework, the security command, and the networksetup command, and unfortunately, none of them seem to allow me to select an 802.1x profile to use for the network. I could leave it to automatically decide, but we've found that it doesn't always work. It will choose some MobileMe certificate or other "trusted" cert over the existing 802.1x profile. All in all it seems to be fairly buggy, if you ask me.

In my searching I was able to find a post by "Big Mac on Campus" who works at Clemson, who produced a somewhat similar solution, but it's quite a bit larger than I would have expected or liked it to be, and it uses PEAP authentication, not TLS, so he doesn't address the certificate issue. He also goes about solving problems by directly editing the .plist files.

http://bigmaconcampus.wordpress.com/2009/08/27/wireless-installer-the-next-generation/

All in all I was hoping for a much simpler solution, as it will take quite a bit more work to go through the code for this other solution and tweak it to my needs. But unfortunately, it seems like there just isn't one out there.



[ Reply to This | # ]
10.6: Add wireless networks from command line
Authored by: dzurn on Feb 02, '12 12:28:17PM
Sorry to dredge up an old thread, but I was just looking for a way to set up an Airport network automatically and found this on ol' reliable MacOSXHints.com!

I found that networksetup includes a command to import a profile. From man networksetup:

     -import8021xProfiles service path
             Imports the 802.1x profiles for the specified service.

Now I'm just trying to figure out how to specify 128-bit WEP, and name the network and password. ;)

---
Madness takes its toll.
Please have exact change.


[ Reply to This | # ]
10.6: Add wireless networks from command line
Authored by: hellomrzebra415 on Oct 12, '10 12:33:31PM

I see there is a place for password, but what about username? We are using wpa2 enterprise which needs login and password.



[ Reply to This | # ]