def get_public_ip(addresses, version=4):
        """Return either the devices public IPv4 or IPv6 address.
        """
        for addr in addresses:
            if addr['public'] and addr['address_family'] == version:
                return addr.get('address')
        return None
Return either the devices public IPv4 or IPv6 address.