def get_own_ip ( ) : sock = socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) try : sock . connect ( ( "8.8.8.8" , 80 ) ) except socket . gaierror : ip_ = "127.0.0.1" else : ip_ = sock . getsockname ( ) [ 0 ] finally : sock . close ( ) return ip_
how yo print hostname of ip in python
Get the host s ip number .
def get_own_ip():
    """Get the host's ip number.
    """
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    try:
        sock.connect(("8.8.8.8", 80))
    except socket.gaierror:
        ip_ = "127.0.0.1"
    else:
        ip_ = sock.getsockname()[0]
    finally:
        sock.close()
    return ip_