Connect to a Wireless Network from the Command Line

Apr 12, 2011 - 11 Comments

Using the powerful ‘networksetup’ utility, we can connect to wireless networks directly from the command line. The syntax you’ll want to use is as follows:

networksetup -setairportnetwork Airport [router SSID] [password]

For example, if I’m connecting to a wireless router with an SSID of “OutsideWorld” and the password is “68broncos” this would be the syntax:

networksetup -setairportnetwork Airport OutsideWorld 68broncos

You could combine this tip with using aliases to create shortcuts and eliminate the need for the lengthy command. An example to put in your .bash_profile would be:

alias publicwifi='networksetup -setairportnetwork Airport OutsideWorld 68broncos'

Now you would only have to type ‘publicwifi’ at the command line and you’ll connect to the specified router. Remember that this will store the wireless access points password in plain text, so if someone was able to access your .bash_profile they would also be able to see that wireless routers password.

If you want to explore more of what networksetup has to offer, type ‘man networksetup’ and you’ll find an astonishing amount of powerful uses for the command line utility.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: David Mendez in Command Line, Mac OS X

11 Comments

» Comments RSS Feed

  1. Chuck says:

    Useful but I think it is easier to just use the pulldown menu

  2. James says:

    Uh… why would you do this?

    Don’t get me wrong, I have found CLIs more efficient than GUIs for many networking and programming environments. However, I agree with Chuck – you’re taking something simple and doing it in a more complicated manner.

    • Ian says:

      Using the CLI you can script things out in a powerful fashion. For example, you could script connecting to another router once bandwidth has hit a limit. It’s also just useful for troubleshooting wireless problems.

  3. Alberto says:

    Ah ah, sometime I wonder why some people use a Mac……

  4. Dennis says:

    I know some people who are much faster with the command line than someone else would be with mouse/dropdown-box…

    If you just have to do only one thing, a mouseclick might be faster, but if you do all your tasks with the command line, after a short time you’ll beat every GUI-User…

  5. [...] [via] Tags: Alias, Netzwerk, OS X, Terminal, Tipp, WLAN « Previous Post blog comments powered by Disqus /* [...]

  6. To answer all those folks who are asking why? The reason I need this is because I’m using an iBook as a home server (I’m cheap, I already had the machine, so relax) and my wireless network every few days flaps. Its not too much of a problem for an interactive user, but its a pain to go dig out the laptop and reconnect it, especially since it is under the bed.

    Yeah, I should figure out why the wireless is flapping, but I don’t see any obvious reasons, and it isn’t that much of a problem..

    • Abe Lincoln says:

      Perhaps the laptop being under a bed is overheating, that… or the dust bunnies are out to get you

      • I’m pretty sure its not overheating anymore than an iBook G4 usually would. I’ve got it on raised so that it has airflow on all sides, and I keep the lid open. I’m pretty sure that its just some quirk with the wireless router and computer interacting.

  7. Corey says:

    what if the SSID is not broadcasting (hidden Wireless Network) is there another variable ?

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates