Created
February 13, 2023 18:15
-
-
Save mkaraki/42f062dbd2f1665b965486894f568bbe to your computer and use it in GitHub Desktop.
Generate v6 subnet mask for each section per cidr
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
<?php | |
for ($cidr = 0; $cidr <= 128; $cidr++) { | |
$maskvalue = []; | |
$imaskvalue = []; | |
$netaddr = []; | |
for ($i = 0; $i < 8; $i++) { | |
$maskbit = $cidr - ($i * 16); | |
if ($maskbit < 0) $maskbit = 0; | |
if ($maskbit > 16) $maskbit = 16; | |
$maskbitstr = str_pad(str_repeat('1', $maskbit), 16, '0'); | |
$maskvalue[$i] = intval(bindec($maskbitstr)); | |
$imaskvalue[$i] = abs($maskvalue[$i] - 65535); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment