Improved code to get the public (external) IP