Created
June 4, 2023 16:02
-
-
Save abn/c4165a6d288e5f7137bdec5a4db199d1 to your computer and use it in GitHub Desktop.
A patched version of socket.getfqdn() based on the patch provided in cpython#49254
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
# patched socket.getfqdn() - see https://github.com/python/cpython/issues/49254 | |
def getfqdn(name=''): | |
"""Get fully qualified domain name from name. | |
An empty argument is interpreted as meaning the local host. | |
""" | |
name = name.strip() | |
if not name or name == '0.0.0.0': | |
name = socket.gethostname() | |
try: | |
addrs = socket.getaddrinfo(name, None, 0, socket.SOCK_DGRAM, 0, socket.AI_CANONNAME) | |
except socket.error: | |
pass | |
else: | |
for addr in addrs: | |
if addr[3]: | |
name = addr[3] | |
break | |
return name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment