import socket


def get_rdns_lookup(ip):
    """
    Takes an IP address adn looks up what the reverse DNS is if it exists.
    """
    try:
        rdns = socket.gethostbyaddr(ip)
        if rdns[0] == rdns[2][0]:
            rdns = 'NO DATA'
        else:
            rdns = rdns[0]
    except Exception as e:  # pragma: no cover
        rdns = 'NO DATA'
    return rdns