I'm assuming you're using a wireless router. As a test, go into to the router setup menu and turn off all security. In other words, turn off WEP, WPA, WPA2, and so on. Also make sure the router is broadcasting the SSID. Next, open System Preferences, Network, on the iMac and select Airport. Check the Network name making sure it's the same as being broadcast by the router.
Also clear off any passwords that you may have in the airport settings.
Once you're able to get on the net, you can reset any security in the router (WPA or above preferred) and do the same in airport settings.
If all that doesn't help, try attaching your router to the iMac via an ethernet cable. That should get you on the net if nothing else is wrong with either the router, modem, or your iMac. Let us know.
Regards.