;

How to Get The Fully Qualified Domain Name of a Host Using Python


Tutorialsrack 02/09/2020 Python

In this article, you will learn how to get the fully qualified domain name of a host using Python. To get the fully qualified domain name of the host, we used the socket.getfqdn() method from the python built-in module socket.

Here is the source code of the program to get the fully qualified domain name of a host.

How to Get The Fully Qualified Domain Name of a Host Using Python
# How to Get The Fully Qualified Domain Name Of a Host Using Python
 
# Import Module
import socket
 
# defining a function
def GetDomainName(hostaddress):
    # Get the fully qualified domain name
    return socket.getfqdn(hostaddress)
 
 
print("Fully qualified domain name: ",GetDomainName('209.191.88.254'))
print("Fully qualified domain name: ",GetDomainName('www.yahoo.com'))
print("Fully qualified domain name: ",GetDomainName('www.google.com'))
print("Fully qualified domain name: ",GetDomainName('www.gmail.com'))
Output

Fully qualified domain name:  d.mx.mail.yahoo.com

Fully qualified domain name:  media-router-fp73.prod.media.vip.sg3.yahoo.com

Fully qualified domain name:  del03s13-in-f4.1e100.net

Fully qualified domain name:  del11s04-in-f5.1e100.net

To get the Fully Qualified Domain name of the computer, you need to run this code as given below:

To Get the Fully qualified domain name of the computer
# To Get the Fully qualified domain name of the computer
 
# Import Module
import socket
 
# Get the fully qualified domain name
fqdn = socket.getfqdn()
 
# Print the Output
print("Fully qualified domain name of this computer is: ", fqdn)

I hope this article will help you to understand how to get the fully qualified domain name of a host using Python.

Share your valuable feedback, please post your comment at the bottom of this article. Thank you!


Related Posts



Comments

Recent Posts
Tags