code: def local_ip():
      
      try:
          ip = socket.gethostbyname(socket.gethostname())
      except IOError:
          ip = socket.gethostbyname('localhost')
      if ip.startswith('127.'):
          ip = get_local_ip_by_interfaces()
          if ip is None:
              ip = get_local_ip_by_socket()
      return ip
docs: Get the local network IP of this machine