There are several IP address to location services. For instance: http://www.ip-adress.com/ip_tracer/ and http://www.ip2location.com/demo.aspx . How do they collect their data? (i.e. mail surveys [yeah, probably not], tech-mobiles driving around and gathering information) What data do they usually gather?
You'll have to read more about Geolocation Software and their different types of data gathering techniques. Most online services aimed at geolocation do a regional internet registry lookup, in the U.S. it would be ARIN. There are various types of techniques and accuracy in finding out an actual location, some even combine methods in order to give you their best guess of where the IP is coming from.