Ip and location tracker

i know a little php and i’ve used mysql to an extent.

i’d like to make a script that automatically adds visitors ip’s to a database. (if they already visited then it ignores their ips) and then displays a list on the website of locations that have visited the website. (united states, japan, etc) kind of like youtubes viewers by country.

where should i start? is there a tutorial somewhere that’ll make this easier or has someone already supplied a open source script for this?

thanks for any help