mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
add bind(0,''); better way of guessing our fully qualified hostname
This commit is contained in:
parent
8d2033f08b
commit
303c179b92
1 changed files with 8 additions and 1 deletions
|
@ -211,6 +211,7 @@ class FTP:
|
||||||
def makeport(self):
|
def makeport(self):
|
||||||
global nextport
|
global nextport
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
sock.bind(('', 0))
|
||||||
sock.listen(1)
|
sock.listen(1)
|
||||||
host, port = sock.getsockname()
|
host, port = sock.getsockname()
|
||||||
resp = self.sendport(port)
|
resp = self.sendport(port)
|
||||||
|
@ -234,7 +235,13 @@ class FTP:
|
||||||
# Make sure it is fully qualified
|
# Make sure it is fully qualified
|
||||||
if not '.' in thishost:
|
if not '.' in thishost:
|
||||||
thisaddr = socket.gethostbyname(thishost)
|
thisaddr = socket.gethostbyname(thishost)
|
||||||
thishost = socket.gethostbyaddr(thisaddr)[0]
|
firstname, names, unused = \
|
||||||
|
socket.gethostbyaddr(thisaddr)
|
||||||
|
names.insert(0, firstname)
|
||||||
|
for name in names:
|
||||||
|
if '.' in name:
|
||||||
|
thishost = name
|
||||||
|
break
|
||||||
try:
|
try:
|
||||||
if os.environ.has_key('LOGNAME'):
|
if os.environ.has_key('LOGNAME'):
|
||||||
realuser = os.environ['LOGNAME']
|
realuser = os.environ['LOGNAME']
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue