Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe27a50

Browse files
committed
Added warning that gethostname() doesn't always return fqdn, and show
how to find it using gethostbyaddr().
1 parent 5709dcf commit fe27a50

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

Doc/lib/libsocket.tex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ \section{Built-in Module \sectcode{socket}}
9696
the Python interpreter is currently executing. If you want to know the
9797
current machine's IP address, use
9898
\code{socket.gethostbyname(socket.gethostname())}.
99+
Note: \code{gethostname()} doesn't always return the fully qualified
100+
domain name; use \code{socket.gethostbyaddr(socket.gethostname())}
101+
(see below).
99102
\end{funcdesc}
100103

101104
\begin{funcdesc}{gethostbyaddr}{ip_address}
@@ -105,6 +108,8 @@ \section{Built-in Module \sectcode{socket}}
105108
alternative host names for the same address, and \code{ipaddrlist} is
106109
a list of IP addresses for the same interface on the same
107110
host (most likely containing only a single address).
111+
To find the fully qualified domain name, check \var{hostname} and the
112+
items of \var{aliaslist} for an entry containing at least one period.
108113
\end{funcdesc}
109114

110115
\begin{funcdesc}{getprotobyname}{protocolname}

Doc/libsocket.tex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ \section{Built-in Module \sectcode{socket}}
9696
the Python interpreter is currently executing. If you want to know the
9797
current machine's IP address, use
9898
\code{socket.gethostbyname(socket.gethostname())}.
99+
Note: \code{gethostname()} doesn't always return the fully qualified
100+
domain name; use \code{socket.gethostbyaddr(socket.gethostname())}
101+
(see below).
99102
\end{funcdesc}
100103

101104
\begin{funcdesc}{gethostbyaddr}{ip_address}
@@ -105,6 +108,8 @@ \section{Built-in Module \sectcode{socket}}
105108
alternative host names for the same address, and \code{ipaddrlist} is
106109
a list of IP addresses for the same interface on the same
107110
host (most likely containing only a single address).
111+
To find the fully qualified domain name, check \var{hostname} and the
112+
items of \var{aliaslist} for an entry containing at least one period.
108113
\end{funcdesc}
109114

110115
\begin{funcdesc}{getprotobyname}{protocolname}

0 commit comments

Comments
 (0)