GIT.Harvie.CZ
/
mirrors
/
Programs.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6cdaf0d
)
Spravne zarovnani delek ipv6 adres reverzu
author
Tomas Mudrunka
<tomas@mudrunka.cz>
Thu, 8 Oct 2020 07:37:28 +0000
(09:37 +0200)
committer
Tomas Mudrunka
<tomas@mudrunka.cz>
Thu, 8 Oct 2020 07:37:28 +0000
(09:37 +0200)
php/ipv6wildcard.php
patch
|
blob
|
blame
|
history
diff --git
a/php/ipv6wildcard.php
b/php/ipv6wildcard.php
index 289c0fdbe394f925f50c4453e7b76c06eb1728c9..458b3b3e61b0fb195c038210320f154257c8a738 100755
(executable)
--- a/
php/ipv6wildcard.php
+++ b/
php/ipv6wildcard.php
@@
-8,6
+8,8
@@
* addresses to be used for as reverse DNS records
*/
function ipv6_prefix2wildcards($address, $prefix) {
* addresses to be used for as reverse DNS records
*/
function ipv6_prefix2wildcards($address, $prefix) {
+ //Special case of /0 prefix
+ if($prefix == 0) return ['*'];
//Parse ip and prefix
echo("IPv6 prefix: ".$address."/".$prefix."\n");
//Parse ip and prefix
echo("IPv6 prefix: ".$address."/".$prefix."\n");
@@
-16,9
+18,10
@@
function ipv6_prefix2wildcards($address, $prefix) {
$a = gmp_import($addr);
//Separate maskable octets
$a = gmp_import($addr);
//Separate maskable octets
- $pref_hex = ceil($pref / 4)*4; //Prefix rounded up to full octets
- $pref_rem = $pref_hex - $pref; //Remainder of prefix
- echo("Rounding prefix: ".$pref_hex."-".$pref_rem."\n");
+ $pref_hex = ceil($pref / 4); //Number of prefix octets
+ $pref_bin = $pref_hex*4; //Number of prefix octets in bits
+ $pref_rem = $pref_bin - $pref; //Remainder of prefix
+ echo("Rounding prefix: ".$pref_bin."-".$pref_rem."\n");
$a = gmp_div_q($a, gmp_pow(2,128-$prefix)); //Truncate to just prefix
$a = gmp_mul($a, gmp_pow(2,$pref_rem)); //Fill remaining bits in last wildcard octet with zeros
$a = gmp_div_q($a, gmp_pow(2,128-$prefix)); //Truncate to just prefix
$a = gmp_mul($a, gmp_pow(2,$pref_rem)); //Fill remaining bits in last wildcard octet with zeros
@@
-28,12
+31,19
@@
function ipv6_prefix2wildcards($address, $prefix) {
for($i = 0; $i < (2**$pref_rem) ; $i++) {
//echo("ADDED: ".$i." = ".decbin($i)."\n");
$ap = gmp_or($a, gmp_init($i));
for($i = 0; $i < (2**$pref_rem) ; $i++) {
//echo("ADDED: ".$i." = ".decbin($i)."\n");
$ap = gmp_or($a, gmp_init($i));
- $wildcards[] = $ap;
+ $w = gmp_strval($ap, 16);
+ $w = str_repeat('0', $pref_hex-strlen($w)).$w;
+ if(strlen($w) < 32) $w.='*';
+ $wildcards[] = $w;
}
return $wildcards;
}
}
return $wildcards;
}
+function ipv6_string2rev($str) {
+ return implode('.',str_split(strrev($str)));
+}
+
if(isset($argv[2])) {
$wcs = ipv6_prefix2wildcards($argv[1],$argv[2]);
} else {
if(isset($argv[2])) {
$wcs = ipv6_prefix2wildcards($argv[1],$argv[2]);
} else {
@@
-42,6
+52,10
@@
if(isset($argv[2])) {
echo("\n");
foreach($wcs as $w) {
echo("\n");
foreach($wcs as $w) {
- //echo(gmp_strval($w, 2)."* :-)\n");
- echo(gmp_strval($w, 16)."*\n");
+ echo($w."\n");
+}
+
+echo("\n");
+foreach($wcs as $w) {
+ echo(ipv6_string2rev($w)."\n");
}
}
This page took
0.153056 seconds
and
4
git commands to generate.