So I have done extensive troubleshooting for my problem. When we moved to our new apartment and had a new fiber optic internet set up with, which came with a new wireless router, all the trouble started. I set the new router to the same network name and password as our previous apartment so all the computers would connect automatically. At that point the macbook froze on startup every time we rebooted. Every time it freezes it happens with the spinning rainbow wheel. I didn't realize it was the wifi, and I ran the hardware and disk tests. Everything came out fine. I completely re-installed the OS. Finally I took the computer to a different location, and every worked fine. It was strange. We had the computer out of the house for about 2 months and everything worked fine. Connecting to many different wireless networks. As soon as we got back to our home, the problem happened again. I ended up turning off our new wifi router. Then the macbook worked perfectly. I made a wifi hotspot with my android phone, and the mac connected to this no problem also.
So then I changed the name and pass of the wifi network. This way the macbook didn't recognize it automatically. The macbook then started up and was perfectly functioning. Then I tried to connect to the newly change wifi, and it immediately froze with the rainbow spinning wheel.
All the other computers have no problem with the new wifi router. It uses WPA2 PSK. This is a very strange problems. I think I found a pose with the same exact problem here: https://discussions.apple.com/thread/2672089?tstart=0
Of course there is no useful fix suggested. I tried deleting the files from the preferences folder but to no avail.
Does anyone know anything about this problem. Of course a fix would be to buy a new wireless router, but this one is brand new, and it seems the problem is with the Mac and not with network.
Anyway any help would be greatly appreciated. Thanks!