IPv6

Revision as of 14:33, 4 October 2023 by David (talk | contribs) (Created page with " ===Local Addresses=== See https://datatracker.ietf.org/doc/html/rfc4193#section-3 The summary is that your subnet is commonly a /64 where the first 8 bits are 0xFD, the next 40 bits are random, and the last 16 bits are a subnet ID of your choosing. The 40 random bits make collisions unlikely. <syntaxhighlight lang="python"> import random prefix = f"{0b11111101:02x}" # 0xfd random_bits = f"{random.getrandbits(40):010x}" # 40 random bits # subnet_id = f"{random.getr...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
\( \newcommand{\P}[]{\unicode{xB6}} \newcommand{\AA}[]{\unicode{x212B}} \newcommand{\empty}[]{\emptyset} \newcommand{\O}[]{\emptyset} \newcommand{\Alpha}[]{Α} \newcommand{\Beta}[]{Β} \newcommand{\Epsilon}[]{Ε} \newcommand{\Iota}[]{Ι} \newcommand{\Kappa}[]{Κ} \newcommand{\Rho}[]{Ρ} \newcommand{\Tau}[]{Τ} \newcommand{\Zeta}[]{Ζ} \newcommand{\Mu}[]{\unicode{x039C}} \newcommand{\Chi}[]{Χ} \newcommand{\Eta}[]{\unicode{x0397}} \newcommand{\Nu}[]{\unicode{x039D}} \newcommand{\Omicron}[]{\unicode{x039F}} \DeclareMathOperator{\sgn}{sgn} \def\oiint{\mathop{\vcenter{\mathchoice{\huge\unicode{x222F}\,}{\unicode{x222F}}{\unicode{x222F}}{\unicode{x222F}}}\,}\nolimits} \def\oiiint{\mathop{\vcenter{\mathchoice{\huge\unicode{x2230}\,}{\unicode{x2230}}{\unicode{x2230}}{\unicode{x2230}}}\,}\nolimits} \)

Local Addresses

See https://datatracker.ietf.org/doc/html/rfc4193#section-3

The summary is that your subnet is commonly a /64 where the first 8 bits are 0xFD, the next 40 bits are random, and the last 16 bits are a subnet ID of your choosing. The 40 random bits make collisions unlikely.

import random <br />

prefix = f"{0b11111101:02x}" # 0xfd
random_bits = f"{random.getrandbits(40):010x}" # 40 random bits
# subnet_id = f"{random.getrandbits(16):04x}" # 16 bits of your choice
subnet_id = "0000"
ip = prefix + random_bits + subnet_id
ip = ":".join((ip[4*x:4*x+4] for x in range(len(ip)//4)))
print(ip)