'Reduce run time DNS look with socket - Python

I look to get Forward and Reverse look DNS look up for an address, i.e. a URL. I write below function with socket but time performance is about 4.5 second.

I would appreciate help and recommendation to improve time performance.

def DNS_lookups(address):
    '''
    Forward and reverse look DNS look up for address = URL
    - forward: URL --> ip - check if is live
    - reverse: ip  --> domain name
    '''
    
    try:
        ip_add = socket.gethostbyname(address)
        try:
            domain_name = socket.gethostbyaddr(ip_add)[0]
        except socket.herror:
            # print('oops')
            return [ip_add, 'host not found']
        
    except socket.gaierror:
        # print('oops')
        return ['False', 'NA']
    #finally: # else:  
        # domain_name = socket.gethostbyaddr(socket.gethostbyname(address))[0]
    return [ip_add, domain_name]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source