In short this piece of code makes a remote call to ipinfo.io to get that information from the IP
const lookup = (callback) => {
loadJSONP('ipinfo.io', 'sendBack');
window.sendBack = (resp) => {
const countryCode = (resp && resp.country) ? resp.country : '';
callback(countryCode);
}
};
As you always need to have a lookup table to relate IP to country.