Rev 5 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5 | Rev 46 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * IPv4 functions for PHP |
4 | * IPv4 functions for PHP |
5 | * Copyright 2012-2021 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2012-2022 Daniel Marschall, ViaThinkSoft |
6 | * Version 2021-05-21 |
6 | * Version 2022-09-18 |
7 | * |
7 | * |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
9 | * you may not use this file except in compliance with the License. |
9 | * you may not use this file except in compliance with the License. |
10 | * You may obtain a copy of the License at |
10 | * You may obtain a copy of the License at |
11 | * |
11 | * |
Line 400... | Line 400... | ||
400 | if (strpos($line, '/') !== false) { |
400 | if (strpos($line, '/') !== false) { |
401 | $rng = ipv4_cidr2range($line); |
401 | $rng = ipv4_cidr2range($line); |
402 | } else { |
402 | } else { |
403 | $rng = explode('-', $line); |
403 | $rng = explode('-', $line); |
404 | $rng[0] = trim($rng[0]); |
404 | $rng[0] = trim($rng[0]); |
405 | $rng[1] = trim($rng[1]); |
405 | if (isset($rng[1])) $rng[1] = trim($rng[1]); |
406 | $rng[0] = ipv4_normalize($rng[0]); |
406 | $rng[0] = ipv4_normalize($rng[0]); |
407 | if (!isset($rng[1])) $rng[1] = $rng[0]; |
407 | if (!isset($rng[1])) $rng[1] = $rng[0]; |
408 | $rng[1] = ipv4_normalize($rng[1]); |
408 | $rng[1] = ipv4_normalize($rng[1]); |
409 | } |
409 | } |
410 | 410 | ||
Line 563... | Line 563... | ||
563 | return long2ip(intval($iplong)); |
563 | return long2ip(intval($iplong)); |
564 | } |
564 | } |
565 | if (strlen($bin) != 128) { |
565 | if (strlen($bin) != 128) { |
566 | return false; |
566 | return false; |
567 | } |
567 | } |
568 | $pad = 128 - strlen($bin); |
568 | //$bin = str_pad($bin, 128, '0', STR_PAD_LEFT); |
569 | for ($i = 1; $i <= $pad; $i++) { |
- | |
570 | $bin = '0'.$bin; |
- | |
571 | } |
- | |
572 | $bits = 0; |
569 | $bits = 0; |
573 | $ipv6 = ''; # added by vts to avoid warning |
570 | $ipv6 = ''; # added by vts to avoid warning |
574 | while ($bits <= 7) { |
571 | while ($bits <= 7) { |
575 | $bin_part = substr($bin,($bits*16),16); |
572 | $bin_part = substr($bin,($bits*16),16); |
576 | $ipv6 .= dechex(bindec($bin_part)) . ':'; |
573 | $ipv6 .= dechex(bindec($bin_part)) . ':'; |