def get_nameservers(ipv4only=True):
    """
    Return a list of nameservers from parsing /etc/resolv.conf.

    If ipv4only is set, filter out ipv6 nameservers. This is because nginx
    freaks out in some formats of ipv6 that otherwise seem ok.
    """
    nameservers = []
    with open("/etc/resolv.conf") as f:
        for line in f:
            if line.strip().startswith("nameserver"):
                nameservers += line.strip().split(" ")[1:]
    if ipv4only:
        nameservers = [n for n in nameservers if ":" not in n]
    return nameservers