def METHOD_NAME(addr):
    num_colons = addr.count(":")
    if num_colons == 0:
        # If no colons exist, return address.
        # Examples:
        #   1.2.3.4 -> 1.2.3.4
        #   foo.com -> foo.com
        return addr
    if num_colons == 1:
        # If one colon exists, return address without port.
        # Examples:
        #   1.2.3.4:567 -> 1.2.3.4
        #   foo.com:123 -> foo.com
        return addr.split(":")[0]
    else:
        # If >1 colon exists, parse ipv6 address.
        left_pos = addr.find("[")
        right_pos = addr.find("]")
        if left_pos != -1 and right_pos != -1:
            # If left and right brackets exist, return inner portion.
            # Examples:
            #   [::]:123 -> ::
            #   [::] -> ::
            return addr[left_pos+1:right_pos]
        else:
            # If no left and right brackets exist, return ipv6 address
            # Examples:
            #   1111:2222:3333:4444:5555:6666:7777:8888 -> 1111:2222:3333:4444:5555:6666:7777:8888
            #   :: -> ::
            return addr