It's different for each game. For Valve games that don't use the P2P server technology (CS 1.6, DoD 1.3, CS:S etc), there will be a list of server IPs that Valve will maintain. I don't believe that Valve publishes how to to access this list, so you may have to figure that part out yourself using tools like WireShark.
Once you get this list, you will need to connect to each IP using a specific port and figure out how to ask each server for its current information (map, player count, etc). This part will likely be using UDP. Again, I doubt that Valve or other companies will publish how to do this and you'll have to figure it out yourself.
I'll elaborate on what I said at the top: this process will be roughly the same for all games with a server list, but the ports and protocols will all be different for different developers.
As for listing which server is in what country, hopefully the server provides that information, but if it doesn't you can use something like GeoIP: http://en.wikipedia.org/wiki/Geolocation_software