- The method getfqdn()of Python's socket module returns the fully qualified domain name of a host.
- The Python example program invokes getfqdn() twice. The first call to the getfqdn()is without passing any argument. In this case, it returns the fully qualified domain name of the machine name on which the Python interpreter is running. The return value is MyMachine.Local.The Local is the pseudo-top-level domain for hostnames in local area networks.
- The second invocation of getfqdn()is done with “example.net” as the argument, which returns “example.net” as the output. The .net part denotes the top-level domain (TLD). The name of the host is example.
# Get the fully qualified domain name
fqdn = socket.getfqdn()
print("Fully qualified domain name of this computer is:");
# Get FQN for example.net
hostName = "www.example.net";
fqdn = socket.getfqdn(hostName);
print("Fully qualified domain name of %s is:"%hostName);
Fully qualified domain name of this computer is:
Fully qualified domain name of www.example.net is: