Skip to content

Instantly share code, notes, and snippets.

@glyzinie
Created November 22, 2024 03:53
Show Gist options
  • Save glyzinie/9d7b0ba600246600f315df56f1fb67fa to your computer and use it in GitHub Desktop.
Save glyzinie/9d7b0ba600246600f315df56f1fb67fa to your computer and use it in GitHub Desktop.
// Run this with [Bun](https://bun.sh)
const CF_IP_PREFIX = "2606:4700::";
const ipv4 = Bun.argv[2]?.split(".").map(Number);
if (
!ipv4 ||
ipv4.length !== 4 ||
ipv4.some((n) => Number.isNaN(n) || n < 0 || n > 255)
) {
console.log("Usage: bun run index.ts <ipv4>");
process.exit(1);
}
const ipv6 = CF_IP_PREFIX + ipv4
.map((n, i) => (i === 2 ? ":" : "") + n.toString(16).padStart(2, "0"))
.join("");
console.log(ipv6);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment