They don't have to look for a top level domain country code. There are vendors that have databases which will provide the location of a specified IP address.
I believe that all of the scenarios in your post are correct.
Originally Posted by
Majuki
What I don't know exactly is how T-mobile knows you're international if calling over WiFi. I assume they do a reverse DNS lookup and check to see if there's a country code on the top level domain. It would be interesting to see if places like Guam, CNMI, and American Samoa would register as 'US' since they're unlikely to use a top level domain that would indicate a specific location in the US.