code: def get_host_addresses(use_ipv4, use_ipv6):
      
      addresses = []
      for interface in netifaces.interfaces():
          ifaddresses = netifaces.ifaddresses(interface)
          for address in ifaddresses.get(socket.AF_INET, []):
              if use_ipv4 and address['addr'] != '127.0.0.1':
                  addresses.append(address['addr'])
          for address in ifaddresses.get(socket.AF_INET6, []):
              if use_ipv6 and address['addr'] != '::1' and '%' not in address['addr']:
                  addresses.append(address['addr'])
      return addresses
docs: Get local IP addresses.