def get_host_ip()

in src/sagemaker_xgboost_container/dmlc_patch/tracker.py [0:0]


def get_host_ip(hostIP=None):
    if hostIP is None or hostIP == "auto":
        hostIP = "ip"

    if hostIP == "dns":
        hostIP = socket.getfqdn()
    elif hostIP == "ip":
        from socket import gaierror

        try:
            hostIP = socket.gethostbyname(socket.getfqdn())
        except gaierror:
            logger.warn("gethostbyname(socket.getfqdn()) failed... trying on hostname()")
            hostIP = socket.gethostbyname(socket.gethostname())
        if hostIP.startswith("127."):
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            # doesn't have to be reachable
            s.connect(("10.255.255.255", 1))
            hostIP = s.getsockname()[0]
    return hostIP