I should have been a little more clear. Ping cannot resolve a hostname like that.
the command should be:
ping www.apple.com (leave the http:// off of the hostname).
You could also try the following:
1. trash the system config PLISTS and reboot (note you will loose your iMac's network settings, so if you are using static entry's IP address, DNS, etc be sure to write them down before attempting this).
Open a terminal and do the following commands:
mkdir ~/Desktop/old_sys_configs
sudo cp -pR /Library/Preferences/SystemConfiguration/* ~/Desktop/old_sys_configs
cd /Library/Preferences/SystemConfiguration/
rm -rf *.plist
The above commands will save a copy of your current network settings to a folder on the Desktop. Reboot your iMac. When your Mac comes back, try to connect to your Ethernet network or Wi-Fi network and see what happens.
If you wanted to restore your old network configuration (since the files are on the desktop) all you would need to do is the following in terminal:
sudo cp -R ~/Desktop/old_sys_configs/* /Library/Preferences/SystemConfiguration/
And then reboot.