You can do this online using the nominatim service or offline.

For example you could get a europe.osm file, filter for place=city/town/village with osmfilter.

For getting the state/country you can evalute the is_in Tag, or search for the nearest addr: node.