import re


def validate_hostname(hostname):
    """
    Validate a hostname string.  This allows standard hostnames and IPv4
    addresses.

    :param hostname: The hostname to validate.
    :return: Boolean: True if valid, False if invalid
    """
    # Hostname length is limited.
    if len(hostname) > 255:
        return False

    # Hostname labels may consist of numbers, letters and hyphens, but may not
    # end or begin with a hyphen.
    allowed = re.compile("(?!-)[a-z\d-]{1,63}(?<!-)$", re.IGNORECASE)
    return all(allowed.match(x) for x in hostname.split("."))