These days there are a bunch of services that allow a website owner to check the location of an IP - the MaxMind GeoIP database is the most established, new contenders in this area are the Google Location-API and the Creative Commons licensed WorldIP. [via]
All of those try to know - to various degrees of success - the location of the current user based on rather large databases that map IPs to locations. Those locations are either actual town-level locations or just return the country/country code.