Wi-Fi dropping and losing Internet connection are two totally separate things.
If your Wi-Fi drops, you lose connectivity to everything on your network. If your Internet drops, you only lose connection to the outside world, your internal network is still good.
Below is a general picture of a home network with Intenet.
(The cable modem used here can also be a DSL router, a fiber connection, or any other high speed connection, this explanation isn't limited to cable modems)
If the connection between the Cable Modem and the Internet dropped, you would still be able to communicate with all the other devices on the the network itself. For instance, you would still be able to print a document or stream music to your entertainment console from your iTunes library on your computer.
First, let's determine if it is your Wi-Fi or your Internet.
Get your IP address and the IP address of your router. Under Settings --> Network, you will see your IP and Router. (I am using Ethernet here, but it is exactly the same for Wi-Fi)
In this case, my router's IP is 192.168.10.1
Testing the Wi-Fi connection.
If your Wi-Fi drops, first it will appear disconnected (red or yellow dot) like mine is in the picture. You can also try and ping the router.
In Terminal, type the following command:
ping -c 5 <your router IP>
ping -c 5 192.168.10.1 <-------- Example using my IP
You should see results that look like (the top half) of the picture below. If it fails, it will look like the bottom half with the "Request timeout" error
If it's successful, then your network is working. If not, then there is a problem with either your Wi-Fi adapter or with your modem/router iteself
If it's working, trying pinging Google or one of the public DNS Servers. Enter the following in Terminal:
ping -c 5 www.google.com <----- This should work, but if DNS is failing, try the next line
ping -c 5 22.214.171.124 <------ If you can't hit this, your connection to the internet is failing
If it fails now, then your Internet is not working and that will require a service call to your provider.
One other thing you can try is connecting an Ethernet cable directly to the router/modem and disabling your Wi-Fi. If you no longer have drops in service, we will know that you have an issue with Wi-Fi. It could still be either your computer or the router/modem, but we will know what is working and what is not.
How can we tell if it is a Wi-Fi issue with either the router/modem or with your iMac?
This is where another device comes in. If you have an iPhone or another computer or a tablet, check to see if you have connectivity when your computer's connection drops.
- If you don't then it is the router/modem. Time for a service call with your service provider
- If you do, then chances are it's your computer. More diagnostics and checking of settings, but time to setup up an appointment with Apple service.