Tiny Deathstars of Foulness

If you need to push a wireless network into your image in Mac OS X, you can do so with the networksetup command. Networksetup has a few options that are specifically geared to working with wireless networks. In order to obtain a list of all of the networks that your system has used, you will use the networksetup command along with the -listpreferredwirelessnetworks option. The man page lists that you will follow this command with the hardwareport. The hardwareport is the name of the wireless network adapter, which can be seen in the System Preference pane.

Finding the hardwareport

By default this is called AirPort, so the default command to see all wireless networks in your preferred list would be:

networksetup -listpreferredwirelessnetworks AirPort In order to remove items from the list you will use the -removepreferredwirelessnetwork option. Here, you will run networksetup followed by the option and then the hardwareport followed by the name of the network to be removed. So to remove a network called Linksys: networksetup -removepreferredwirelessnetwork AirPort Linksys You can also remove all of them by using the -removeallpreferredwirelessnetworks option followed by the hardwareport: networksetup -removeallpreferredwirelessnetworks AirPort And then of course, the most useful is to add networks, which uses the -addpreferredwirelessnetworkatindex option. You would follow this with the hardwareport, then the network, then the index number you’d like it to be assigned to (or 0 if you don’t know) and then the security type of the wireless network (OPEN, WEP, WPA, WPA2, WPAE or WPA2E). For example, to add a network called drpepper that is a wide open network: networksetup -addpreferredwirelessnetworkatindex AirPort drpepper 0 NONE Or, if it was WPA with a password set to thedrisin: networksetup -addpreferredwirelessnetworkatindex AirPort drpepper 0 WPA thedrisin Note: For a new image I prefer to begin with 0 and then work my way up numerically when adding networks into the list.

September 21st, 2010

Posted In: Mac OS X, Mass Deployment

Tags: , , , , , , , , , , , ,

  • James Blair

    The ‘-addpreferredwirelessnetworkatindex’ argument doesnt seem to be available in the Leopard version of networksetup, is there a comparable argument for that version? Also, Is there anyway to do this for those older Tiger machines which don’t have network setup at all?

    • Snow Leopard and up for that one. You can probably crawl through the plist and add it, but that might be some heavy lifting…

  • School dir

    I couldn’t get this to work on 10.5.8
    Commend not recognized.

  • Pingback: Setting preferred wireless networks from the command line. « Der Flounder()