7.11. dns — DNS protocol

The dns module provides functions to resolve a hostname ip address.

7.11.1. Functions

dns.client_hostname_lookup(host, ms)

Resolving IP address of a remote host using the specified timeout in ms. If lookup fails, the ip 0.0.0.0 will be returned.

import dns
import time

print("DNS example")

# Resolving IP address of a remote host using the specified timeout in ms
# If lookup fails, the ip 0.0.0.0 will be returned
ip = dns.client_hostname_lookup("www.google.com", 5000)

print ("Server IP Address is: " + str(ip))

while True:
    time.sleep(5)