| Conditions | 5 |
| Paths | 5 |
| Total Lines | 15 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 3 | function ip2bin($ip) |
||
| 4 | { |
||
| 5 | if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false) |
||
| 6 | return base_convert(ip2long($ip),10,2); |
||
| 7 | if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) |
||
| 8 | return false; |
||
| 9 | if(($ip_n = inet_pton($ip)) === false) return false; |
||
| 10 | $bits = 15; |
||
| 11 | $ipbin = ''; |
||
| 12 | while ($bits >= 0) { |
||
| 13 | $bin = sprintf("%08b",(ord($ip_n[$bits]))); |
||
| 14 | $ipbin = $bin.$ipbin; |
||
| 15 | $bits--; |
||
| 16 | } |
||
| 17 | return $ipbin; |
||
| 18 | } |
||
| 24 |