Created
November 22, 2024 03:53
-
-
Save glyzinie/9d7b0ba600246600f315df56f1fb67fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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