Mac – How to get a Mac to auto-reconnect to a wifi network

macwireless-networking

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?

Best Answer

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 <networkName> with the network's name and <passwordToNetwork> 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
Related Question