Just the title, what the difference between them?
In python, socket.gethostbyname(socket.gethostname())
and socket.gethostbyname(socket.getfqdn())
return different results on my computer.
getfqdn() is using information provided in the file /etc/hosts while socket. gethostname() only prints data from the result of the system call uname() ; basically you could say the one asks the network module while the other asks the kernel.
The gethostname function returns the name of the local host into the buffer specified by the name parameter. The host name is returned as a null-terminated string. The form of the host name is dependent on the Windows Sockets provider—it can be a simple host name, or it can be a fully qualified domain name.
From documentation,
socket.gethostname
returns a string containing the hostname of the machine where the Python interpreter is currently executing.
socket.getfqdn
returns a fully qualified domain name if it's available or gethostname
otherwise.
Fully qualified domain name is a domain name that specifies its exact location in the tree hierarchy of the DNS. From wikipedia examples:
For example, given a device with a local hostname myhost and a parent domain name example.com, the fully qualified domain name is myhost.example.com.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With