Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a Mac Mini Server that's disconnecting every few days or so from the wifi network. There may be other parameters causing the initial disconnection (such as the wireless router being rebooted) but the Mac doesn't automatically reconnect.

It's a major problem since it's a server machine that's suddenly becomes unavailable until someone goes to the machine physically and uses the wifi menu to reconnect manually to the network. I should mention that although the wifi network is WPA2, manually reconnecting doesn't involve re-entering the password so there's no obvious reason why it doesn't reconnect automatically.

How can I get the Mac to periodically try and reconnect to a specified wifi network?

share|improve this question
    
Is the network in question defined as Preferred? Have you checked in System Preferences > Network that "Remember any network this computer has joined" is checked and "Disconnect from wireless networks when logging out" is unchecked? You could also try to delete and recreate the network connection. –  harrymc Oct 10 '11 at 17:39
    
where exactly is the "Disconnect from wireless networks when logging out" option? It's running Lion. –  GJ. Oct 12 '11 at 14:34
    
Apparently in Advanced settings. –  harrymc Oct 12 '11 at 20:54
    
not to make you paranoid or anything, but the only way to crack WPA2 encryption is to sniff the authentication packets (when a computer connects) and the most common way to do that is to de-authenticate one of the machines and sniff the network when it re-connects. –  Nate Koppenhaver Oct 13 '11 at 23:32

1 Answer 1

up vote 3 down vote accepted
+50

Here is an Applescript and shell script to check if Airport is connected and if not to connect it.

if (do shell script "networksetup -getinfo Wi-Fi | grep -c 'IP address:'") = 1 then
    do shell script "networksetup -setairportnetwork en1 <networkName> <passwordToNetwork>"
end if

#!/bin/bash
if [ $(networksetup -getinfo Wi-Fi | grep -c 'IP address:') = '1' ]
then $(networksetup -setairportnetwork en1 <networkName> <passwordToNetwork>)
fi

Replace with the network's name and with its password. The "en1" should be correct if you have not changed your Network devices.

Now all you need to do is loop this or call it to check the connection.

Nevertheless airport should automatically reconnect if the connection is lost. Maybe try resetting all network preferences and see if that works.

How to completely reset your Network Preferences : Turn Airport off. Close System Preferences. Navigate to : /Library/Preferences/SystemConfiguration/ Make a copy, then delete the following files :

com.apple.airport.preferences.plist
com.apple.network.*
com.apple.smb.server.plist
NetworkInterfaces.plist
share|improve this answer
    
thanks. why use an applescript though? it seems to lend itself more to a shell script perhaps one that runs every minute or so using launchd. –  GJ. Oct 18 '11 at 11:15
    
also, how do you "reset all network preferences" ? –  GJ. Oct 18 '11 at 11:15
    
This could be done with a shell script. Although I'm better at Applescript so I wrote it in Applescript. I'll see if I can write it in a shell script. I've also updated the post on reseting network preferences. –  Kassym Dorsel Oct 18 '11 at 13:42
    
Improved the script and added a shell script. –  Kassym Dorsel Oct 18 '11 at 14:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.