Skip to content

Instantly share code, notes, and snippets.

@codigoconjuan
Created February 19, 2026 23:31
Show Gist options
  • Select an option

  • Save codigoconjuan/dab91f1729e071e6afd648de0a412d44 to your computer and use it in GitHub Desktop.

Select an option

Save codigoconjuan/dab91f1729e071e6afd648de0a412d44 to your computer and use it in GitHub Desktop.
Identificar IP
import { headers } from "next/headers";
export async function getClientIp(): Promise<string> {
const headersList = await headers();
return (
headersList.get("cf-connecting-ip") || // Cloudflare
headersList.get("x-vercel-forwarded-for") || // Vercel
headersList.get("x-real-ip") || // Nginx / proxies
headersList.get("x-forwarded-for")?.split(",")[0].trim() || // standard
headersList.get("remote-addr") || // fallback local/dev
"unknown"
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment