Python Glossary Русский

all Python 3socketfunction

socket.getfqdn()

names and addresses

Returns the fully qualified domain name for a name or address; without an argument, for this machine.

Syntax

socket.getfqdn(name='') -> str

Internally it does a reverse DNS lookup through gethostbyaddr and picks the first name containing a dot, so it may take seconds and its result depends on /etc/hosts and the DNS setup of the machine. If nothing is found there is no error: the given name comes back unchanged, so 'success' does not mean the name is real.

Examples

import socket
print(socket.getfqdn('127.0.0.1'))  # → ? localhost
print(socket.getfqdn())  # → ? my-laptop.example.lan

See also

Open in the full glossarydocs.python.orgReport an inaccuracy