def local_address(fallback):
"""Returns the local address of this computer."""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 53))
interface = s.getsockname()[0]
s.close()
except OSError:
interface = fallback
logging.info(
'Cannot connect to network determine interface, using fallback "{}"'.
format(fallback))
return interface
评论列表
文章目录