Group C

Q16: Write a program for DNS lookup. Given an IP address input, it should return URL and vice versa.

DNS Lookup Program - IP to URL and URL to IP

Solution and implementation for Q16 from Computer Networks (cnl).

16_dns_lookup.py Download
import socket

choice = input("Enter '1' for Domain to IP or '2' for IP to Domain: ")

if choice == '1':
    domain = input("Enter domain name: ")
    ip = socket.gethostbyname(domain)
    print("IP address of", domain, "is:", ip)

elif choice == '2':
    ip = input("Enter IP address: ")
    host = socket.gethostbyaddr(ip)
    print("Domain name of", ip, "is:", host[0])

else:
    print("Invalid choice.")

Other Questions in Computer Networks

See All Available Questions
Download