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

Skip to content

Commit 2d2785a

Browse files
author
Peter Schneider-Kamp
committed
updated occurences of fqdn algorithm (closes patch #101197)
1 parent 77c9f50 commit 2d2785a

3 files changed

Lines changed: 8 additions & 36 deletions

File tree

Lib/BaseHTTPServer.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,7 @@ def server_bind(self):
9393
"""Override server_bind to store the server name."""
9494
SocketServer.TCPServer.server_bind(self)
9595
host, port = self.socket.getsockname()
96-
if not host or host == '0.0.0.0':
97-
host = socket.gethostname()
98-
try:
99-
hostname, hostnames, hostaddrs = socket.gethostbyaddr(host)
100-
except socket.error:
101-
hostname = host
102-
else:
103-
if '.' not in hostname:
104-
for host in hostnames:
105-
if '.' in host:
106-
hostname = host
107-
break
108-
self.server_name = hostname
96+
self.server_name = socket.getfqdn(host)
10997
self.server_port = port
11098

11199

@@ -418,16 +406,8 @@ def address_string(self):
418406
419407
"""
420408

421-
(host, port) = self.client_address
422-
try:
423-
name, names, addresses = socket.gethostbyaddr(host)
424-
except socket.error, msg:
425-
return host
426-
names.insert(0, name)
427-
for name in names:
428-
if '.' in name: return name
429-
return names[0]
430-
409+
host, port = self.client_address
410+
return socket.getfqdn(host)
431411

432412
# Essentially static class variables
433413

Lib/ftplib.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141

4242
# Import SOCKS module if it exists, else standard socket module socket
4343
try:
44-
import SOCKS; socket = SOCKS
44+
import SOCKS; socket = SOCKS; del SOCKS # import SOCKS as socket
45+
from socket import getfqdn; socket.getfqdn = getfqdn; del getfqdn
4546
except ImportError:
4647
import socket
4748

@@ -291,17 +292,8 @@ def login(self, user = '', passwd = '', acct = ''):
291292
if not passwd: passwd = ''
292293
if not acct: acct = ''
293294
if user == 'anonymous' and passwd in ('', '-'):
294-
thishost = socket.gethostname()
295-
# Make sure it is fully qualified
296-
if not '.' in thishost:
297-
thisaddr = socket.gethostbyname(thishost)
298-
firstname, names, unused = \
299-
socket.gethostbyaddr(thisaddr)
300-
names.insert(0, firstname)
301-
for name in names:
302-
if '.' in name:
303-
thishost = name
304-
break
295+
# get fully qualified domain name of local host
296+
thishost = socket.getfqdn()
305297
try:
306298
if os.environ.has_key('LOGNAME'):
307299
realuser = os.environ['LOGNAME']

Lib/socket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def getfqdn(name=''):
8585
is returned.
8686
"""
8787
name = name.strip()
88-
if len(name) == 0:
88+
if not name or name == '0.0.0.0':
8989
name = gethostname()
9090
try:
9191
hostname, aliases, ipaddrs = gethostbyaddr(name)

0 commit comments

Comments
 (0)