Get Country by IP

Hello, I am trying to create a server search list and I would like the server list to automatically detect the server region or country by the IP address, I know that is possible but I’m not sure how that is done, does anyone have experience on similar implementations?