code: def get_public_address(gateway_ip=None, retry=9):
      
      if gateway_ip is None:
          gateway_ip = get_gateway_addr()
      addr_request = PublicAddressRequest()
      addr_response = send_request_with_retry(gateway_ip, addr_request,
                                              response_data_class=
                                              PublicAddressResponse,
                                              retry=retry, response_size=12)
      if addr_response.result != 0:
          # sys.stderr.write("NAT-PMP error %d: %s\n" %
          #                  (addr_response.result,
          #                   error_str(addr_response.result)))
          # sys.stderr.flush()
          raise NATPMPResultError(addr_response.result,
                                  error_str(addr_response.result), addr_response)
      addr = addr_response.ip
      return addr
docs: A high-level function that returns the public interface IP of
         the current host by querying the NAT-PMP gateway.  IP is
         returned as string.
         
         Takes two possible keyword arguments:
              gateway_ip - the IP to the NAT-PMP compatible gateway.
                           Defaults to using auto-detection function
                           get_gateway_addr()
              retry - the number of times to retry the request if unsuccessful.
                      Defaults to 9 as per specification.