import socket


def get_hostname_by_addr(addr):
    """return hostname for host at address"""
    try:
        (hostname, aliaslist, ipaddrlist) = socket.gethostbyaddr(
            socket.gethostbyname(addr)
        )
        return hostname
    except:
        return addr