Your best shot is using an api. There are some providers:
https://api-ninjas.com/api/city
http://geodb-cities-api.wirefreethought.com/
Probably also available at Openstreetmap, Google, Azure or AWS
Countries are fetch from API